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;
}
目录
相关文章
codeforces 285C - Building Permutation
题目大意是有一个含n个数的数组,你可以通过+1或者-1的操作使得其中的数是1--n中的数,且没有重复的数。 既然是这样的题意,那么我就应该把原数组中的数尽量往他最接近1--n中的位置放,然后求差绝对值之和,但有多个数,怎么使他们和最小,这样就要对其进行排序了,直接按大小给它们安排好位置,然后计算。
44 0
UVa11565 - Simple Equations
UVa11565 - Simple Equations
58 0
UVa11296 - Counting Solutions to an Integral Equation(枚举技巧)
UVa11296 - Counting Solutions to an Integral Equation(枚举技巧)
59 0
|
存储
LeetCode 329. Longest Increasing Path in a Matrix
给定一个整数矩阵,找出最长递增路径的长度。 对于每个单元格,你可以往上,下,左,右四个方向移动。 你不能在对角线方向上移动或移动到边界外(即不允许环绕)。
86 0
LeetCode 329. Longest Increasing Path in a Matrix
|
人工智能 BI
CodeForces - 1485D Multiples and Power Differences (构造+lcm)
CodeForces - 1485D Multiples and Power Differences (构造+lcm)
92 0
|
算法
[LeetCode]--60. Permutation Sequence
The set [1,2,3,…,n] contains a total of n! unique permutations. By listing and labeling all of the permutations in order, We get the following sequence (ie, for n = 3): 1."123" 2."132" 3
1085 1
|
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.
1312 0