본문 바로가기
728x90
반응형

프로그래머스 코딩테스트4

c++(cpp) 프로그래머스 - 코딩 테스트 : 약수의 합 #include #include using namespace std; int solution(int n) { int answer = 0; for(int i = 1 ; i 2022. 8. 11.
c++(cpp) 프로그래머스 - 코딩 테스트 : 하샤드 수 #include #include using namespace std; bool solution(int x) { bool answer = true; int x1 = x; int result=0; while(x > 0) { result += x % 10; x = x / 10 ; } if(x1 % result != 0) { answer = false; } else answer = true; return answer; } 2022. 7. 28.
c++(cpp) 프로그래머스 : 코딩테스트 - 신규 아이디 추천 #include #include #include #include using namespace std; string solution(string new_id) { string answer = ""; // 소문자 치환 for(char& ch : new_id) { ch = tolower(ch); } // 소문자, 숫자, -, _, . 제외한 모든 문자 제거 for(char ch : new_id) { if(isalpha(ch) || isdigit(ch) || strchr("-_.", ch)) answer += ch; } // .가 두개 이상 -> 하나로 int idx = -1; while((idx = answer.find("..")) != -1) //answer안에 ..이 있을 때 까지 돌기 { answer.r.. 2022. 7. 26.
c++(cpp) 프로그래머스 : 코딩테스트 - 로또의 최고 순위와 최저 순위 약간 노가다로 푼 것 같지만.. #include #include using namespace std; vector solution(vector lottos, vector win_nums) { vector answer; int count = 0; int zero = 0; for(int i = 0 ; i < lottos.size(); i++) { if(lottos[i] == 0) { zero += 1; } for(int j = 0 ; j < lottos.size(); j++) { if(lottos[i] == win_nums[j]) { count += 1; } } } if(count + zero == 6) { answer.push_back(1); } else if(count + zero == 5) { answ.. 2022. 7. 26.
728x90
반응형