반응형
https://www.acmicpc.net/problem/2231
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
32
33
34
35
36
37
38
39
40
41
42
43
|
#include<iostream>
using namespace std;
int n;
int sumofnum(int num) {
int val = 0;
while (num != 0) {
val += num % 10;
num = num / 10;
}
return val;
}
int Solve() {
int start = n;
int sum;
int MAX_n = 0;
while (true) {
--start;
sum = sumofnum(start);
if (start + sum < n && start % 10 == 9) return MAX_n;
if (start + sum == n) {
MAX_n = start;
}
if (start == 0) return MAX_n;
}
}
int main(void) {
cin >> n;
cout << Solve();
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|
반응형