basic

A collection of 75 post

Factorial

Problem Enter a natural number N to get the value of N!. N! = n(n-1)(n-2)…2*1. If N=5 then 5!=54321=120. input In the first line, the natural number N (3<=n<=10) is entered. output Print the N factorial value on the first line. Solution plus subtract

Number of Combinations (Memoization)

Problem The equation above is solution for number of combinations. But instead of using this formula, write a program that uses the following equation to find the combinatorial number using recursion. input The first line contains the natural numbers n (3<=n<=33) and r (0<=r<=n). output Prints the…

Finding Permutations

Problem If N natural numbers less than or equal to 10 are given, M out of them are selected and all methods are printed out. input The first line is given the natural numbers N(3<=N<=10) and M(2<=M<=N) In the second line, N natural numbers are given in ascending order output Prints the result on the…

Coin Exchange

Problem How can I exchange change for the smallest number of coins when several units of coins are given as follows? Each unit of coins can be used indefinitely. input In the first line, the number of types of coins N (1<=N<=12) is given. The second line is given N types of coins, and the next line…

Find Duplicate Permutations

Problem There are marbles numbered from 1 to N. Of these, duplicates are allowed, and all methods of selecting M times and arranging them are printed out. input The first line is given the natural numbers N(3<=N<=10) and M(2<=M<=N). output Prints the result on the first line. Prints the last total…

Finding the Maximum Score (DFS)

Problem In order to get good grades in this information olympiad, Hyun-soo is going to solve the N problems given by the teacher. Each question is given a score for solving it and the time it takes to solve it. We need to get the maximum score out of N problems within the time limit M. (The problem…

Dog Riding

Problem Cheol-su wants to go to the market with his dog. But his truck cannot carry more than C kilograms. Cheol-su wants to burn his dog the most without going over C. Given N dogs and the weight W of each dog, write a program to find the heaviest weight that Cheolsu can carry in a truck. input The…

Subsets with Equal Sum (DFS)

Problem Given a set of natural numbers with N elements, When this set is divided into two subsets, if there is a case where the sum of the elements of the two subsets is equal, “YES” is output, Otherwise, write a program that prints “NO”. The two subsets divisible by two are disjoint sets, and the…

Subset (DFS)

Problem Given a natural number N, write a program that prints all subsets of a set with elements 1 through N. input The first line is given a natural number N (1<=N<=10). output From the first line, the subsets are printed in the same order as in the output example below, one for each line However…

Binary Tree Traversal (Depth First Search)

Problem Practice forward and backward traversal of the binary tree as shown in the figure below. output Pre-traversal output: Inter-traversal output: Post-traversal output: Solution Pre traversal Inter traversal Post traversal

Recursive Binary

Problem Write a program that converts decimal number N into binary number and outputs it. However, it must be output using a recursive function. input The first line is given a decimal number N (1<=N<=1,000). output Print the binary number on the first line. Solution

Recursive Function

Problem Write a program that outputs 1 to N using a recursive function when a natural number N is input. input In the first line, an integer N (3<=N<=10) is entered. output print on the first line Solution

Stable Setup (Decision Algorithm)

Problem N stables are on a vertical line. Each stable has the coordinates of x1, x2, x3, …, xN, and there is no overlap of coordinates between the stables. Hyeonsu has C horses, who don’t like being close to each other. Each stable can only hold one horse, and we want the horses to be placed in the…

Music Video (Decision Tree Algorithm)

Problem Genie Records is trying to sell the live video of the undisputed singer Youngpil Cho on DVD. A total of N songs are included in a DVD, and when recording on a DVD, the order in live should be maintained. Our singer Youngpil Cho hates the change of order. That is, in order to record songs…

Binary Search

Problem Any N numbers are given as input. Write a program that sorts N numbers in ascending order and, given M, which is one of the N numbers, uses binary search to find the number of M in the sorted state. However, there are no duplicate values. input The first line gives the natural numbers N (…

Meeting Room Assignment

Problem Conference Room There is one conference room, and we want to create a conference room usage table for n conferences that we want to use. Find the maximum number of meetings that are given the time and can use the conference room without overlapping each meeting. However, once a meeting…

Wedding Ceremony

Problem Hyun-soo is getting married next month. Hyun-soo rents a place for the wedding reception and plans to hold it for three days without a break. Hyeon-soo requested information about the time of N friends attending the reception in advance. Each friend told Hyeon-soo what time he would arrive…

Coordinate Alignment

Problem Given N coordinates on a plane (x, y), write a program that sorts all coordinates in ascending order. The sort criterion is first sorted by the x value, and if the x value is the same, it is sorted by the y value. input The first line is given the number of coordinates N (3<=N<=100,00…

Naughty Hyeonsu

Problem A new semester has begun. Hyunsoo was so excited to meet his new mate. There are N students in Hyunsoo’s class. In order to assign class numbers to the class, the teacher placed the class in a row on the playground, starting with the tallest student. Class numbers are numbered from 1 to N…

Least Recently Used

Problem Cache memory is a high-speed temporary memory between the CPU and main memory (DRAM). It is very expensive and has a small capacity, so it must be used efficiently. The cache memory usage rules of the computer of the withdrawal follow the LRU algorithm. LRU algorithm is an abbreviation of…

Insertion Sort

Problem Write a program that sorts in ascending order when N numbers are input and outputs them. The sorting method is insertion sort. input The first line is given a natural number N (1<=N<=100). In the second line, N natural numbers are entered with a space between them. Each natural number is in…

Special Sort

Problem If N integers are entered, you must sort the entered values. Negative integers must be on the front and positive integers on the back. Also, the order of positive and negative integers should not change. input Integer N (5<=N<=100) is given to the first line, and integers including negative…

Bubble Sort

Problem Write a program that sorts in ascending order when N numbers are input and outputs them. The sorting method is bubble sort. input The first line is given a natural number N (1<=N<=100) In the second line, N natural numbers are entered with a space between them. Each natural number is in the…

Selection Sort

Problem Write a program that sorts in ascending order when N numbers are input and outputs them. The sorting method is selection sort. input The first line is given a natural number N (1<=N<=100) In the second line, N natural numbers are entered with a space between them. Each natural number is in…

Curriculum Design

Problem Hyeonsu must plan a one-year course. There are compulsory subjects in class. These compulsory courses must be completed, and the order is set. If there are total subjects A, B, C, D, E, F, G, and the compulsory subjects are given as CBA, the compulsory subjects are C, B, and A subjects, and…

Save the Princess

Problem The only daughter Princess of the neighboring country of the information kingdom has been captured by a monster in the forest. There are N princes in the information kingdom, and they both agree to go rescue the princess. The king of the information kingdom decides which prince to go to…

Iron Stick

Problem I am trying to cut several iron rods with a laser. For efficient operation, the iron rods are stacked from the bottom up, and the laser is fired vertically from above to cut the iron rods. The arrangement of the iron rod and laser satisfies the following conditions. An iron rod can only be…

Postfix Operation

Problem Write a program that outputs the result of the operation given a postfix expression. If 3(5+2)-9 is expressed as a postfix expression, it is expressed as 352+9- and the result is 12. input Postfix expression is given in the first line. The length of the expression cannot exceed 5…

Crane Game

Problem Jordi, a game developer, wants to make a crane puppet machine into a mobile game. In order to increase the fun of the game, Jordi tries to reflect the screen composition and rules in the game logic as follows. The game screen is an N x N square grid of 1 x 1 squares with a crane on the top…

Remove Parentheses Letter (Stack)

Problem Write a program that removes all characters between parentheses ( ) in the input string and prints only the remaining characters. input A string of parentheses is entered on the first line The length of the string does not exceed 100. output Only the remaining characters are printed…

Correct Parenthesis (Stack)

Problem If parentheses are entered, it outputs “YES” if it is a valid parenthesis, and “NO” if it is not correct. (())() This is the correct placement of the pair of parentheses, but (()())) is not the correct parentheses. input A string of parentheses is entered on the first line The maximum length…

Find All Anagrams (Hash, Two-Pointer, Sliding Window)

Problem Write a program that counts the number of substrings of S that are anagrams and T strings in S string. When identifying anagrams, case is sensitive. Substrings must be contiguous strings. input The first S string is entered on the first line, and the T string is entered on the second line…

Anagram (Hash)

Problem Anagrams Two words are said to be anagrams when two strings differ in alphabetical order, but their composition matches. For example, AbaAeCe and baeeACA have different alphabets, but if you look at their composition, they are A(2), a(1), b(1), C(1), e(2), the alphabets and their numbers…

Class President (Hash)

Problem A, B, C, D, and E candidates registered as candidates to select the class president. The ballot is written with the symbol (alphabetically) of the candidate chosen by the students in the class, and the teacher announces the symbol. After the teacher’s presentation, write a program that…

Maximum Sales

Problem Hyun-soo’s father runs a bakery. Hyeon-soo’s father gave him the sales record for N days and told him to find the maximum sales for K consecutive days. If N=10, the sales record for 10 days is as follows. In this case, if K = 3 The maximum sales for 3 consecutive days is 11+20+25=560,000 won…

Consecutive Sub Sequence 2

Problem You are given a sequence of N numbers. Write a program to find how many times in this sequence the sum of consecutive subsequences is less than or equal to a specific number M. If N=5, M=5 and the sequence is A continuous subsequence whose sum is 5 or less is {1}, {3}, {1}, {2}, {3}, {1,…

Consecutive Sub Sequence

Problem You are given a sequence of N numbers. Write a program to count how many times in this sequence the sum of consecutive subsequences is a specific number M. If N=8, M=6 and the sequence is There are three consecutive subsequences whose sum is 6: {2, 1, 3}, {1, 3, 1, 1}, and {3, 1, 1,…

Finding Commons

Problem Given two sets A and B, write a program that extracts the common elements of the two sets and outputs them in ascending order. input The first line gives the size N of set A (1<=N<=30,000). The second line gives N elements. Duplicate elements are not given. The third line gives the size M of…

Concatenate Two Arrays

Problem Given two arrays sorted in ascending order, write a program that merges the two arrays in ascending order and prints them. input The first line gives the size N (1<=N<=100) of the first array. The second line gives the N array elements in ascending order. The third line gives the size M (…

Kth Largest Number

Problem Hyeonsu has N cards with natural numbers between 1 and 100. There can be multiple cards of the same number. Hyeon-soo draws 3 of them and tries to record the sum of the numbers on each card. Record all three possible draws. Write a program that prints the Kth largest number among recorded…

Graduation Gift

Problem The teacher is going to give a graduation gift to the classmates who are graduating this year. Students were asked to choose a product they wanted from an online shopping mall and submit the price and shipping cost of that product. Teachers have a limited budget. Write a program to find out…

Mentoring

Problem Hyunsoo’s class teacher wants to create a mentoring system to improve the students’ math scores. Mentoring is a pair of mentors (students helping) and mentees (students receiving help), and the mentor helps the mentee study math. The teacher selects a mentor and a mentee based on the M…

Reverse Prime Number

Problem Write a program that flips each natural number when N natural numbers are input and outputs the prime number if the reversed number is prime. For example, flipping 32 is 23, and 23 is a prime number. Then it outputs 23. If you flip 910, you have to number it as 19. Consecutive zeros from the…

Sum of Digits

Problem Write a program that, when N natural numbers are input, finds the sum of the digits of each natural number, and outputs the natural number with the largest sum. If the sum of digits is the same, the answer is the number with the larger original number. If 235 and 1234 can be the answer at…

String Compression

Problem Write a program that compresses a character string by inputting a character string consisting of uppercase letters and writing the number of repetitions to the right of the repeated character when the same character is repeated continuously.
However, if the number of repetitions is…

Shortest Distance Between Strings

Problem Given a string s and a letter t, write a program that prints the minimum distance each letter of string is from the letter . input The first line is given the string and the letter . Strings and characters are given only in lower case. The length of the string does not exceed 100. output…

Extract Numbers

Problem Given a string with a mixture of letters and numbers, only the numbers are extracted and a natural number is created in that order. If you extract only numbers from “tge0a1h205er”, it is 0, 1, 2, 0, 5, and if you make a natural number from this, it becomes 1205. The natural number produced…

Valid Palindrome

Problem A string that is the same whether read from the front or from the back is called a palindrome. Write a program that outputs “YES” if a string is input and “NO” if it is a palindrome. However, when examining palindromes, only alphabets are used to check palindromes, and case is not sensitive…

Palindrome String

Problem A string that is the same when read from the front or read from the back is called a palindrome. When a string is input, write a program that outputs “YES” if the string is a palindrome string, and “NO” if it is not a palindrome string. However, it is not case sensitive when checking…

Count Peaks

Problem Map information is given on an N*N grid. Each grid is marked with the height of that area. The number on each grid that is greater than its top, bottom, left, and right numbers is the peak area. Write a program to find out how many peak regions there are. It is assumed that the edges of the…

Max Grid Sum

Problem Numbers are written on the 5*5 grid as shown below. Given a grid of N*N, output the largest of the sum of each row, the sum of each column, and the sum of the two diagonals. input A natural number N is given in the first line (1<=N<=50). From the second line to the N lines, each line is…

Ranking

Problem Write a program that outputs each student’s rank in the order in which they are entered when the Korean language scores of N (1<=N<=100) students are entered. input N (3<=N<=1000) is input in the first line, and N integers representing the Korean score are input in the second line. If the…

Counting Score

Problem An OX problem is a problem that has two possible answers: right or wrong. In the case of consecutive correct answers in a test made of multiple OX questions, it was decided to calculate the score as follows to give additional points. If the first question is correct, it is counted as 1 point…

Rock Scissor Paper

Problem Two people, A and B, play a rock-paper-scissors game. A total of N games are played, and if A wins, output A, and if B wins, output B. In case of a tie, D is output. Scissors, rock, and paper information will be set to 1: Scissors, 2: Rock, and 3: Paper. For example, if N=5 Round 1 2 3 4…

Visible Students

Problem The teacher lined up N (1<=N<=1000) students. Write a program to find the number of students that the teacher standing in front can see when the heights of the students standing in a line are given in order from the front. (If it is larger than the people standing in front, it is visible, if…

Larger Number

Problem Write a program that takes N (1<=N<=100) integers as input and outputs only the number that is greater than the number immediately preceding itself. (The first number is unconditionally printed.) input A natural number N is given in the first line, and N integers are entered in the next line…

Remove Duplicates Words

Problem Write a program that removes duplicated strings when N strings are input and outputs them. The output string maintains the original input order. input A natural number N is given in the first line (3<=N<=30). Starting from the second line, N strings are given. The length of the string does…

Taste a Little Bit of Tailwind-css for Beginner

Introduction Recently, there is buzzing alert all-around about Tailwind-css. Why? Let’s skim it a little bit here. Installation First, set up the basic environment CMD Edit the script line in package.json package.json Generate folder from the root folder. Then, Create the file inside and fill the…

The Middle Letter

Problem Write a program that prints the middle letter of a word (string) in lowercase letters when it is entered. However, if the length of a word is even, the middle two characters are printed. input A string is entered on the first line. The length of the string does not exceed 100. output Prints…

The Longest Word

Problem Write a program that prints the longest of N strings when inputted. input A natural number N is given in the first line (3<=N<=30). Starting from the second line, N strings are given. The length of the string does not exceed 100. Each string has a different length. output Print the longest…

Convert String Case

Problem Write a program that receives a string with both uppercase and lowercase letters as input and converts uppercase letters to lowercase letters and lowercase letters to uppercase letters. input A string is entered on the first line. The length of the string does not exceed 100. output On the…

To Uppercase

Problem Write a program that receives a string with both uppercase and lowercase letters as input and outputs the string by unifying all uppercase letters. input A string is entered on the first line. The length of the string does not exceed 100. output A unified character string with uppercase…

Find-Uppercase

Problem Write a program that takes a string as input and finds how many uppercase letters in that string. input A string is entered on the first line. The length of the string does not exceed 100. output Prints the number of uppercase letters on the first line. Solution using using code

Find String

Problem Write a program that receives a single string, receives a specific character, and finds out how many of that specific character exists in the inputted string. The length of the string does not exceed 100. input A string is given on the first line, and a character is given on the second line…

A to '#'

Problem Write a program that outputs an English word consisting of uppercase letters by replacing all ‘A’ in the word with ’#‘. input A string is entered in the first line. output Prints the changed word on the first line. Solution using using

7 Dwarfs

Problem A crisis came to Snow White, who was living peacefully with the seven dwarfs to escape the queen. There were nine dwarfs who returned from work instead of seven. All nine dwarfs claimed to be the protagonists of “Snow White and the Seven Dwarfs.” Snow White, who had great mathematical…

10-Day-Rotation

Problem From June 1st, the Seoul Metropolitan Government will implement the 10 car system to prevent traffic congestion. The 10 car system prohibits the operation of the car if the first digit of the car number matches the first digit of the date For example, if the day digit of the car number is…

Odd Number

Problem Given 7 natural numbers, write a program to select all odd natural numbers, find the sum, and find the smallest of the odd numbers. For example, given 7 natural numbers 12, 77, 38, 41, 53, 92, 85, the odd numbers among them are 77, 41, 53, 85, so the sum is Therefore, the minimum value…

Finding-the-Minimum

Problem Given 7 numbers, write a program that prints the smallest of those numbers. input Seven numbers are given in the first line. output Print the smallest value on the first line. Solution using using first value using & Dot spread using

Print the sum from 1 to N

Problem Write a program that outputs the sum from 1 to N when a natural number N is input. input A natural number N less than or equal to 20 is entered in the first line. output Prints the sum from 1 to N on the first line. Solution using

Number of Pencils

Problem One dozen pencils is 12. Write a program that calculates the number of pencils needed when N students enter the number of students, assuming that one pencil is distributed to each student. input A natural number N less than or equal to 1000 is entered in the first line. output Print the…

Identify Triangle

Problem Given three bars of different lengths (A, B, C), “YES” is output if these three bars can form a triangle, and “NO” if they cannot be made. input The first line gives you 100 different lengths of bars A, B, and C. output Print “YES” and “NO” on the first line. Solution using using using

Min of Three

Problem Write a program that accepts natural numbers A, B, and C less than or equal to 100 and prints the smallest of the three numbers. (don’t use sort) input Three natural numbers less than or equal to 100 are entered in the first line. output Print the smallest number on the first line. Solution…

Remove Duplicates

Problem Write a program that removes duplicate characters and outputs when a single lowercase character string is input. Each character in the stripped string retains the order of the original string. input A string is entered on the first line. output Prints a string with duplicate characters…

JavaScript Tips for Algorithm

String Tips Light cloning Use regexp for .replace(a,b) is exchange first letter of first argument to second argument. For convert every matching letter, put the letter inside regexp, . example Convert Number There are a lot of ways to convert strings to numbers, but is recommended. Plus, It…