#include <string> #include <vector> #include <iostream> using namespace std; int solution(int n) { // 자기 자신 int answer = 1; for(int i = 1; i <= n/2; i++) { int sum = i; for(int j = i+1; j <= n/2+1; j++) { sum += j; // 합이 n인 경우 if(sum == n) { answer++; break; } // 합이 n보다 큰 경우 else if(sum > n) { break; } } } return answer; } | cs |
'Programmers > Level 2' 카테고리의 다른 글
[프로그래머스 2] 카카오 프렌즈 컬러링북 (C/C++) (1) | 2019.10.26 |
---|---|
[프로그래머스 2] 땅따먹기 (C/C++) (0) | 2019.10.25 |
[프로그래머스 2] 다음 큰 숫자 (C/C++) (0) | 2019.10.25 |
[프로그래머스 2] 전화번호 목록 (C/C++) (0) | 2019.10.25 |
[프로그래머스 2] 라면공장 (C/C++) (★★) (0) | 2019.10.25 |