본문 바로가기
300x250

분류 전체보기241

백준 - 1003.피보나치 함수 https://www.acmicpc.net/problem/1003 다음 소스는 N번째 피보나치 수를 구하는 C++ 함수이다. int fibonacci(int n) { if (n == 0) { printf("0"); return 0; } else if (n == 1) { printf("1"); return 1; } else { return fibonacci(n‐1) + fibonacci(n‐2); } } fibonacci(3)을 호출하면 다음과 같은 일이 일어난다. fibonacci(3)은 fibonacci(2)와 fibonacci(1) (첫 번째 호출)을 호출한다. fibonacci(2)는 fibonacci(1) (두 번째 호출)과 fibonacci(0)을 호출한다. 두 번째 호출한 fibonacci(1.. 2021. 7. 4.
Codesignal - buildPalindrome Given a string, find the shortest possible string which can be achieved by adding characters to the end of initial string to make it a palindrome. Example For st = "abcdc", the output should be buildPalindrome(st) = "abcdcba". Input/Output [execution time limit] 20 seconds (swift) [input] string stGuaranteed constraints: 3 ≤ st.length ≤ 10. A string consisting of lowercase English letters. [outp.. 2021. 5. 6.
Codesignal - firstDigit Find the leftmost digit that occurs in a given string. Example For inputString = “var_1__Int”, the output should be firstDigit(inputString) = ‘1’; For inputString = “q2q-q”, the output should be firstDigit(inputString) = ‘2’; For inputString = “0ss”, the output should be firstDigit(inputString) = ‘0’. Input/Output [execution time limit] 20 seconds (swift) [input] string inputString A string cont.. 2021. 5. 6.
Codesignal - find Email Domain An email address such as "John.Smith@example.com" is made up of a local part ("John.Smith"), an "@" symbol, then a domain part ("example.com"). The domain name part of an email address may only consist of letters, digits, hyphens and dots. The local part, however, also allows a lot of different special characters. Here you can look at several examples of correct and incorrect email addresses. Gi.. 2021. 5. 6.
Codesignal - extractEachKth Given array of integers, remove each kth element from it. Example For inputArray = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] and k = 3, the output should be extractEachKth(inputArray, k) = [1, 2, 4, 5, 7, 8, 10]. Input/Output [execution time limit] 20 seconds (swift) [input] array.integer inputArray Guaranteed constraints: 5 ≤ inputArray.length ≤ 15, -20 ≤ inputArray[i] ≤ 20. [input] integer k Guaranteed .. 2021. 5. 3.
Codesignal - evenDigingsOnly Check if all digits of the given integer are even. Example For n = 248622, the output should be evenDigitsOnly(n) = true; For n = 642386, the output should be evenDigitsOnly(n) = false. Input/Output [execution time limit] 20 seconds (swift) [input] integer n Guaranteed constraints: 1 ≤ n ≤ 109. [output] boolean true if all digits of n are even, false otherwise. 풀이 주어지는 숫자의 각 자리수에 해당하는 숫자가 짝수일때만 .. 2021. 5. 3.
Codesignal - digitDegree Let's define digit degree of some positive integer as the number of times we need to replace this number with the sum of its digits until we get to a one digit number. Given an integer, find its digit degree. Example For n = 5, the output should be digitDegree(n) = 0; For n = 100, the output should be digitDegree(n) = 1. 1 + 0 + 0 = 1. For n = 91, the output should be digitDegree(n) = 2. 9 + 1 =.. 2021. 5. 2.
Codesignal - differentSymbolsNaive Given a string, find the number of different characters in it. Example For s = "cabca", the output should be differentSymbolsNaive(s) = 3. There are 3 different characters a, b and c. Input/Output [execution time limit] 20 seconds (swift) [input] string sGuaranteed constraints: 3 ≤ s.length ≤ 1000. A string of lowercase English letters. [output] integer 설명 주어지는 문자열에서 서로다른 문자의 수를 리턴하라 풀이 Set의 중복 .. 2021. 5. 2.
Codesignal - depositProfit You have deposited a specific amount of money into your bank account. Each year your balance increases at the same growth rate. With the assumption that you don't make any additional deposits, find out how long it would take for your balance to pass a specific threshold. Example For deposit = 100, rate = 20, and threshold = 170, the output should be depositProfit(deposit, rate, threshold) = 3. E.. 2021. 5. 2.
300x250