알고리즘
[프로그래머스] (C++) 숫자의 표현
전문 컨설턴트
2019. 11. 22. 13:44
문제는 이 링크를 타고 가시면 있어요!
이 문제는 비교적 간단하게 풀었어요
- 힌트: 컴퓨터는 사람이 귀찮아 하는 반복적인 수학 계산을 대신 잘해주죠.
#include <iostream>
int solution(int n) {
int answer = 0;
int addNum;
int total;
for (int i = 1; i <= n; i++) {
addNum = i;
total = 0;
while (1) {
total += addNum;
if (total == n) {
answer++;
}
if (total >= n) break;
addNum++;
}
}
return answer;
}