※ 글쓴이는 취미로 코딩을 익혀보는 사람이라 정확하지 않은 내용을 담고 있을 수 있다 ※
이번에 볼 문제는 백준 29543번 문제인 Smooth numbers이다.
문제는 아래 링크를 확인하자.
https://www.acmicpc.net/problem/29543
29543번: Smooth numbers
Let's call positive integer smooth if each of its digits except the first and the last is less then the average of it's two neighbor digits. It means that if $x = a_n \cdot 10^n + a_{n-1} \cdot 10^{n-1} + ... + a_1 \cdot 10 + a_0$ then for each $i = 1 ...
www.acmicpc.net
이 관찰에 따르면 하나의 수에서 감소가 4번 일어나려면
위의 관찰을 토대로 가능한 경우의 답을 구해 문제를 해결하자.
아래는 제출한 소스코드이다.
#include <iostream>
using namespace std;
int N;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> N;
if (N == 1) cout << "9";
else if (N == 2) cout << "99";
else if (N == 3) cout << "989";
else if (N == 4) cout << "9889";
else if (N == 5) cout << "97679";
else if (N == 6) cout << "976679";
else if (N == 7) cout << "9643469";
else if (N == 8) cout << "96433469";
else cout << -1;
}
'BOJ' 카테고리의 다른 글
[BOJ 17619 // C++] 개구리 점프 (0) | 2024.02.17 |
---|---|
[BOJ 18115 // C++] 카드 놓기 (2) | 2024.02.16 |
[BOJ 29542 // C++] Wipe it! (1) | 2024.02.14 |
[BOJ 2567 // C++] 색종이 - 2 (0) | 2024.02.13 |
[BOJ 2578 // C++] 빙고 (1) | 2024.02.12 |