UVa 1583-Digit Generator-AC
2014-12-16 08:30
411 查看
这道题看完题很容易出思路,再想想优化循环,不必从头到尾没个数循环判断,因为最大为10 0000,所以N的generator最小也就比N小5*9=45,所以只需循环判断从N~N-45就行了。保险起见多循环了9个数。
AC代码:
AC代码:
#include <stdio.h> #include <stdlib.h> int main() { int t; int b,n,m,su,i,j; scanf("%d",&t); while(t--) { scanf("%d",&n); m=0; for (i=n-1;i>=n-54;i--) { su=0; b=i; while(b) { su+=b%10; b/=10; } if (i+su==n) m=i; } printf("%d\n",m); } return 0; }
相关文章推荐
- Digit Generator UVa1583
- UVA - 1583 Digit Generator
- UVa 1583 Digit Generator(数学)
- UVa 1583 Digit Generator
- UVA 1583(p52)----Digit Generator
- uva 1583 B - Digit Generator (暴力)
- 最小生成元 (Digit Generator, ACM/ICPC Seoul 2005, UVa1583)
- UVa 1583 - Digit Generator
- UVa-1583 Digit Generator
- UVa 1583 Digit Generator(数)
- Digit Generator—UVa1583
- UVa 1583 - Digit Generator
- UVa-1583 Digit Generator
- 《算法竞赛入门经典2ndEdition 》例题3-5 生成元(Digit Generator, Uva1583)
- UVa 1583 - Digit Generator
- uva_1583_Digit Generator
- UVA 1583 - Digit Generator
- Problem 005——UVa 1583 - Digit Generator
- Digit Generator, ACM/ICPC Seoul 2005, UVa1583
- UVA1583 UVALive3355 Digit Generator【水题+打表】