분류 전체보기
-
Cats and a Mouse해커랭크(HackerRank) 2018. 8. 19. 17:33
1. 문제 2. 알고리즘키워드 - 구현, 그리디 * 문제 풀이 - 두마리의 고양이가 쥐에게 접근하는 거리가 같다면 쥐는 도망 갈 수 있다. - 두마리의 고양이가 쥐에게 접근하는 거리가 다르다면 짧은 거리로 이동하는 고양이가 승리 한다. 3. 코드 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788#include using namespace std; vector split_string(string); /* * Complete the catAndMouse func..
-
Picking Numbers해커랭크(HackerRank) 2018. 8. 19. 17:32
1. 문제 2. 알고리즘키워드 - 구현 3. 코드 12345678910111213141516171819202122232425262728293031323334353637383940#include using namespace std; int pickingNumbers(vector a) { // Complete this function sort(a.begin(), a.end()); const int size = a.size(); int solution = 0; for(int i=0; i a[a_i]; } int result = pickingNumbers(a); cout
-
Designer PDF Viewer해커랭크(HackerRank) 2018. 8. 19. 17:31
1. 문제 입력으로 들어오는 int 배열은 각각의 글자의 높이 정보를 갖고 있다.높이 : 1 3 1 3 1 4 1 3 2 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 7글자 : a b c d e f g h i j k l m n o p q r s t u v w x y z abc 라는 글자가 있다면 각 글자의 높이는 아래와 같다.a = 1b = 3c = 1 높이가 가장 큰 글자 기준으로 highlight 사각형을 그려야 하기 때문에 답 = 글자 수 * 가장 큰 글자 height답 = 3 * 3답 = 9 2. 알고리즘키워드 - 구현 3. 코드 123456789101112131415161718192021222324252627282930#include using namespace std; int de..
-
Utopian Tree해커랭크(HackerRank) 2018. 8. 19. 17:30
1. 문제봄에는 2배로 커지고 여름에는 1씩 증가 된다. 2. 알고리즘키워드 - 구현 3. 코드 12345678910111213141516171819202122232425262728293031#include using namespace std; int utopianTree(int n) { // Complete this function int sol = 1; for(int i =1; i> t; for(int a0 = 0; a0 > n; int result = utopianTree(n); cout
-
Beautiful Days at the Movies해커랭크(HackerRank) 2018. 8. 19. 17:29
1. 문제 2. 알고리즘키워드 - 구현 * 문제 풀이입력 받은 두 수의 합의 차이의 절대 갑이 k 로 나누어 지는 횟수를 출력 하라 3. 코드 12345678910111213141516171819202122232425262728293031323334353637383940#include using namespace std; int reverse(int count) { int cand = count; int sol = 0; while(cand != 0) { int number = cand % 10; sol = sol * 10 + number; cand = cand / 10; } return sol;} int beautifulDays(int i, int j, int k) { // Complete this fu..
-
The Hurdle Race해커랭크(HackerRank) 2018. 8. 19. 17:28
1. 문제 2. 알고리즘키워드 - 구현 * 문제 풀이 입력으로 받는 k 는 dan 이 넘을 수 있는 허들의 높이 이다.입력으로 들어오는 height 배열의 요소는 각 허들의 높이이며 dan 이 넘을 수 있는 허들 보다 크다면 k 의 값을 증가 시켜 줘야 한다. 1. 허들의 height 중 가장 큰 높이를 구한다.2. k 보다 크다면 height - k 를 출력 한다.3. k 보다 작으면 0 을 출력한다. 3. 코드 123456789101112131415161718192021222324252627282930313233#include using namespace std; int hurdleRace(int k, vector height) { // Complete this function const int si..
-
Arrays - DS해커랭크(HackerRank) 2018. 8. 19. 17:27
1. 문제 2. 알고리즘키워드 - 배열, 정렬 3. 코드 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283#include using namespace std; vector split_string(string); /* * Complete the reverseArray function below. */vector reverseArray(vector a) { /* * Write your code here. */ reverse(a.begin(), a.end()); return a;}..