Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |
Tags
- 컴공
- 알고리즘
- 구현
- 정석학술정보관
- 자료구조
- OS
- 그래프
- vector
- c++
- 개발
- 컴퓨터공학과
- 오퍼레이팅시스템
- Computer science
- 문제풀이
- 브루트포스
- 북리뷰
- 코테
- 컴공과
- 정석
- 백준
- cs
- coding
- 너비우선탐색
- bfs
- DP
- Operating System
- 스택
- 코딩
- 오에스
- Stack
Archives
- Today
- Total
Little Jay
[C++] 백준 2231번 분해합 본문
Brute Force 알고리즘 문제
처음에 문제 이해 못해서 엄청 고생했지만
결국 분해합의 생성자는 입력된 값 보다 작다는거를
명심하고 풀기
#include <iostream>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int num, sum, temp;
cin >> num;
for (int i = 1; i < num; ++i) {
sum = i;
temp = i;
while (temp) {
sum += temp % 10;
temp /= 10;
}
if (num == sum) {
cout << i << endl;
return 0;
}
}
cout << 0 << endl;
return 0;
}
'알고리즘 > BOJ' 카테고리의 다른 글
[C++] 백준 1427번 소트인사이드 (0) | 2021.05.04 |
---|---|
[C++] 백준 1316번 요세푸스 문제 (0) | 2021.05.04 |
[C++] 백준 2108번 통계학 (0) | 2021.05.03 |
[C++] 백준 1018번 체스판 다시 칠하기 (0) | 2021.04.06 |
[C++] 백준 2798번 블랙잭 (0) | 2021.04.05 |
Comments