본문 바로가기

전공공부211

(c++) 프로그래머스 "소수 만들기" https://programmers.co.kr/learn/courses/30/lessons/12977 코딩테스트 연습 - 소수 만들기 주어진 숫자 중 3개의 수를 더했을 때 소수가 되는 경우의 개수를 구하려고 합니다. 숫자들이 들어있는 배열 nums가 매개변수로 주어질 때, nums에 있는 숫자들 중 서로 다른 3개를 골라 더했을 때 programmers.co.kr 나의 풀이 #include #include using namespace std; bool sosu(int a) { for (int i = 2; i < a; i++) { if (a % i == 0) return false; } return true; } int solution(vector nums) { int answer = 0; for (in.. 2022. 1. 13.
(c++) 프로그래머스 "124 나라의 숫자" https://programmers.co.kr/learn/courses/30/lessons/12899# 코딩테스트 연습 - 124 나라의 숫자 programmers.co.kr #include #include #include using namespace std; string solution(int n) { string answer = ""; while (n > 3) { if (n % 3 == 0) { answer = "4" + answer; n -= 1; } else { answer = to_string(n % 3) + answer; } n /= 3; } if (n == 3) { answer = "4" + answer; } else { answer = to_string(n) + answer; } retur.. 2022. 1. 12.
(c++) 프로그래머스 멀쩡한 사각형 나의 풀이 #include using namespace std; int gcd(int a, int b) { if (a % b == 0) return b; else return gcd(b, a % b); } long long solution(int w, int h) { long long answer = (long long)w*(long long)h; int min_n = gcd(max(w, h), min(w, h)); answer -= (w + h - min_n); return answer; } 2022. 1. 12.
(c++) 프로그래머스 단체사진 찍기 https://programmers.co.kr/learn/courses/30/lessons/1835 코딩테스트 연습 - 단체사진 찍기 단체사진 찍기 가을을 맞아 카카오프렌즈는 단체로 소풍을 떠났다. 즐거운 시간을 보내고 마지막에 단체사진을 찍기 위해 카메라 앞에 일렬로 나란히 섰다. 그런데 각자가 원하는 배치가 모두 programmers.co.kr 나의 풀이 #include #include #include #include #include using namespace std; bool check(int r_diff, int w_diff, char type) { if (type == '=') { return r_diff == w_diff; } else if (type == ' 2022. 1. 11.