D2. Digit's sum(subtask 2)
time limit per test
2 seconds
memory limit per test
64 megabytes
input
standard input
output
standard output
Andrew was sitting and counting the sum of digits of the number, but while doing that he forgot what the source number was. Help him to restore the original number, if he knows that the sum is n. If there are several variants, find the smallest. Subtask 1 (1 < = n < = 50)Subtask 2 (1 < = n < = 50000)
Input
The only line of input file contains the number n (1 < = n < = 50000)
Output
In a single line of the output file output a single number - the answer to the problem.
Sample test(s)
input
3
output
3
input
10
output
19
codeforces easy round problem D2 - Digit's Sum (subtask 2) solution :
http://codeforces.com/gym/200470/submission/6100648
#include <iostream> #include <cstdio> using namespace std; int main() { int a; long long b[1039999]; scanf("%d", &a); int i=0; while(a) { if(a<10) { b[i]=a; a=a-a; } else { b[i]=9; a=a-9; } i++; } for(int j=i-1; j>=0; j--) printf("%d", b[j]); return 0; }
No comments:
Post a Comment