UVa1583 - Digit Generator

简介: UVa1583 - Digit Generator
#include <iostream>#include <fstream>usingnamespacestd;
voidsolve(intn);
intmain()
{
#ifndef ONLINE_JUDGEifstreamfin("d:\\OJ\\uva_in.txt");
streambuf*old=cin.rdbuf(fin.rdbuf());
#endif // ONLINE_JUDGEintn;
cin>>n;
while (n--) {
intnum;
cin>>num;
solve(num);
    }
#ifndef ONLINE_JUDGEcin.rdbuf(old);
#endif // ONLINE_JUDGEreturn0;
}
voidsolve(intn)
{
intdigits=0;
intnum=n;
while (num) {
digits++;
num/=10;
    }
boolfound=false;
for (inti=n-digits*9; i<n; i++) {
intsum=i;
num=i;
while (num) {
sum+=num%10;
num/=10;
        }
if (sum==n) {
found=true;
cout<<i<<endl;
break;
        }
    }
if (!found) cout<<0<<endl;
}
目录
相关文章
|
10月前
|
机器学习/深度学习
hdu 1061 Rightmost Digit
hdu 1061 Rightmost Digit
24 0
UVa11565 - Simple Equations
UVa11565 - Simple Equations
46 0
Leetcode-Easy 709. To Lower Case
Leetcode-Easy 709. To Lower Case
96 0
Leetcode-Easy 709. To Lower Case
HDOJ(HDU) 1898 Sempr == The Best Problem Solver?(水题、、、)
HDOJ(HDU) 1898 Sempr == The Best Problem Solver?(水题、、、)
120 0
|
Java
2017 Multi-University Training Contest - Team 9 1002&&HDU 6162 Ch’s gift【树链部分+线段树】
Ch’s gift Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1354    Accepted Submission(s): 496 Problem Description Mr.
1290 0