코딩테스트 연습 - Level 1 - 정수 제곱근 판별 https://programmers.co.kr/learn/courses/30/lessons/12934 #include #include #include using namespace std; long long solution(long long n) { long long answer = 0; if(sqrt(n)==(int)sqrt(n)) { answer=pow(sqrt(n)+1,2); } else { answer=-1; } return answer; }
코딩테스트 연습 - Level 1 - 제일 작은 수 제거하기 https://programmers.co.kr/learn/courses/30/lessons/12935 #include #include #include using namespace std; vector solution(vector arr) { vector answer; if(arr.size()==1) { answer.push_back(-1); return answer; } arr.erase(min_element(arr.begin(),arr.end())); return arr; }
코딩테스트 연습 - Level 1 - 짝수와 홀수 https://programmers.co.kr/learn/courses/30/lessons/12937 #include #include using namespace std; string solution(int num) { string answer = ""; if(num%2!=0) { answer="Odd"; } else { answer="Even"; } return answer; }
코딩테스트 연습 - Level 1 - 최대공약수와 최소공배수 https://programmers.co.kr/learn/courses/30/lessons/12940 #include #include using namespace std; vector solution(int n, int m) { vector answer; for(int i=m;i>0;i--) { if(n%i==0&&m%i==0) { answer.push_back(i); break; } } for(int i=m;i
코딩테스트 연습 - Level 1 - 콜라츠 추측 https://programmers.co.kr/learn/courses/30/lessons/12943 #include #include using namespace std; int solution(int num) { int answer = 0; long long n=num; while(n!=1) { if(answer==500) { answer=-1; break; } answer++; if(n%2==0) { n/=2; } else { n=n*3+1; } } return answer; }
코딩테스트 연습 - Level 1 - 평균 구하기 https://programmers.co.kr/learn/courses/30/lessons/12944 #include #include using namespace std; double solution(vector arr) { double answer = 0; for(int i=0;i