본문 바로가기
728x90
반응형
SMALL

전체 글161

[프로그래머스] 짝수의 합 #include #include using namespace std; int solution(int n) { int answer = 0; for(int i=1; i answer += i%2==0 ? i:0; return answer; } 2025. 9. 2.
[프로그래머스] 양꼬치 #include #include using namespace std; int solution(int n, int k) { // 양꼬치 n인분 // 음료수 k개 k -= n/10; return n*12000 + k*2000; } 2025. 9. 2.
[프로그래머스] 배열의 평균값 #include #include using namespace std; double solution(vector numbers) { double answer = 0; for(auto n : numbers) answer += n; return answer/numbers.size(); } 2025. 9. 2.
[프로그래머스] 피자 나눠 먹기(3) #include #include #include int solution(int slice, int n) { //2~10까지 원하는 조각으로 잘라줌 // slice : 피자 조각 수 (2~10) // n : 피자 먹는 사람의 수 // n명의 사람이 최소 한 조각 이상 먹으려면 최소 몇 판의 피자를 시켜야 하는가? return n%slice == 0 ? n/slice : n/slice+1; } 2025. 9. 2.
[프로그래머스] 피자 나눠 먹기(2) #include #include #include int gcd(int a,int b) // a > b { if(b==0) return a; else return gcd(b, a % b); } int lcm(int a,int b) { return a*b/gcd(a,b); } int solution(int n) { //n과 6의 최소 공배수를 구하기 return lcm(n,6)/6; } 2025. 9. 2.
[프로그래머스] 피자 나눠 먹기(1) #include #include #include int solution(int n) { return n%7 == 0 ? n/7 : n/7+1; } 2025. 9. 2.
[프로그래머스] 짝수는 싫어요 #include #include using namespace std; vector solution(int n) { vector answer; for(int i=1; i { if(i%2 !=0) answer.push_back(i); } return answer; } 2025. 9. 1.
[프로그래머스] 최빈값 구하기 (수정중) #include #include #include using namespace std; int solution(vector array) { if(array.size() ==1) return 1; int answer = 0; map arr_map; for(auto a : array) arr_map[a]++; for(auto itr = arr_map.begin(); itr != arr_map.end(); itr++) { if(arr_map.size()==1) return itr->second; if(answer second) answer = itr->se.. 2025. 9. 1.
[프로그래머스] 나머지 구하기, 중앙값 구하기 #include #include using namespace std; int solution(int num1, int num2) { return num1%num2; } #include #include #include using namespace std; int solution(vector array) { sort(array.begin(), array.end()); return array[ array.size() / 2; ]; } 2025. 9. 1.
728x90
반응형
LIST