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;
}
kgduu
+关注
目录
打赏
0
0
0
0
0
分享
相关文章
UVa11565 - Simple Equations
UVa11565 - Simple Equations
65 0
UVa11296 - Counting Solutions to an Integral Equation(枚举技巧)
UVa11296 - Counting Solutions to an Integral Equation(枚举技巧)
67 0
uva442 Matrix Chain Multiplication
uva442 Matrix Chain Multiplication
53 0
Data Structures and Algorithms (English) - 6-17 Shortest Path [4](25 分)
Data Structures and Algorithms (English) - 6-17 Shortest Path [4](25 分)
130 0
Data Structures and Algorithms (English) - 6-16 Shortest Path [3](25 分)
Data Structures and Algorithms (English) - 6-16 Shortest Path [3](25 分)
121 0
Data Structures and Algorithms (English) - 6-11 Shortest Path [2](25 分)
Data Structures and Algorithms (English) - 6-11 Shortest Path [2](25 分)
141 0
Data Structures and Algorithms (English) - 6-11 Shortest Path [1](25 分)
Data Structures and Algorithms (English) - 6-11 Shortest Path [1](25 分)
127 0
Data Structures and Algorithms (English) - 7-9 Huffman Codes(30 分)
Data Structures and Algorithms (English) - 7-9 Huffman Codes(30 分)
118 0
HDOJ 1014 Uniform Generator(公约数问题)
HDOJ 1014 Uniform Generator(公约数问题)
110 0