본문 바로가기

IT/알고리즘90

54] 프로그래머스 3진법 뒤집기 programmers.co.kr/learn/courses/30/lessons/68935 #include #include using namespace std; int solution(int n) { int answer = 0; vector cnt; int a = n; while(a){ cnt.push_back(a %3); a /= 3; } for(int i = cnt.size()-1; i>=0; i--){ answer += cnt[i] * pow(3, cnt.size()-1-i ); } return answer; } 2020. 10. 21.
53] 프로그래머스 이상한 문자 만들기 programmers.co.kr/learn/courses/30/lessons/12930 코딩테스트 연습 - 이상한 문자 만들기 문자열 s는 한 개 이상의 단어로 구성되어 있습니다. 각 단어는 하나 이상의 공백문자로 구분되어 있습니다. 각 단어의 짝수번째 알파벳은 대문자로, 홀수번째 알파벳은 소문자로 바꾼 문자열을 programmers.co.kr #include using namespace std; string solution(string s) { int count = 0; for(int i = 0; i='a' && s[i]='A' && s[i] 2020. 10. 19.
52] 프로그래머스 정수 제곱근 판별 #include using namespace std; long long solution(long long n) { long long answer = 0; if(sqrt(n) - int(sqrt(n)) == 0 ) return pow(sqrt(n)+1, 2) ; else return -1; } 2020. 10. 15.
51] 프로그래머스 콜라츠 추측 #include #include #include using namespace std; int solution(int num2) { int answer = 0; long long num = num2; while(num != 1){ if(num %2 == 0){ num /=2; answer++; } else{ num *= 3; num++; answer++; } if(answer >= 500) break; } if(answer >=500) answer =-1; return answer; } int로 하면 계산 중 int의 범위를 넘어서는 경우가 있기에 long long으로.. 2020. 10. 14.