본문 바로가기

전체 글310

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.
50] 프로그래머스 서울에서 김서방 찾기 programmers.co.kr/learn/courses/30/lessons/12919 코딩테스트 연습 - 서울에서 김서방 찾기 String형 배열 seoul의 element중 Kim의 위치 x를 찾아, 김서방은 x에 있다는 String을 반환하는 함수, solution을 완성하세요. seoul에 Kim은 오직 한 번만 나타나며 잘못된 값이 입력되는 경우는 없습니다. 제 programmers.co.kr #include #include using namespace std; string solution(vector seoul) { string answer = "김서방은 "; for(int i = 0;i [C++] to_string 함수에 대해서 (int to string) 안녕하세요. BlockDMask 입.. 2020. 9. 26.
49★] 프로그래머스 시저 암호 공백이면 그냥 넘어간다 소문자는 소문자에서 돌고( z -> a) 대문자는 대문자에서 돈다,( Z -> A) #include using namespace std; string solution(string s, int n) { for(int i = 0;i='a' && s[i] 122) s[i] += (n-26); else s[i] +=n; } // 대문자 else if(s[i] >= 'A' && s[i] 90){ s[i] -= 26; } } } return s; } 소문자에서 조심 아스키코드는 127까지만 있다.. ? 2020. 9. 17.