章三例题5——UVA 1583 Degit Generator
2017-02-27 00:12
375 查看
题意就是如果x加上x的各个数字的和得到y,则说x是y的生成元,然后告诉y,求x的最小生成元。
然后因为n比较小,然后只用输入一组,直接枚举是可以过的。
据说可以打表,现在还没有接触到
http://blog.csdn.net/a27038/article/details/55048971
代码
然后因为n比较小,然后只用输入一组,直接枚举是可以过的。
据说可以打表,现在还没有接触到
http://blog.csdn.net/a27038/article/details/55048971
代码
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; int main() { int n; scanf("%d",&n); while(n--) { int N; scanf("%d",&N); int len=1; int flag=0; int temp=N; while(temp) { if(temp/10!=0) len++; temp=temp/10; } int j=0; for(int i=N-len*10;i<N;i++) { j=i; int g=i; while(g) { j+=g%10; g=g/10; } if(j==N) { flag=1; cout<<i<<endl; break; } } if(flag==0) printf("0\n"); } return 0; }
相关文章推荐
- 章三例题1 UVA 272
- 章三例题2——UVA 10082
- 章三例题3——UVA 401 Palindromes
- 章三例题4——UVA 340 Master -Mind Hints
- 章三例题6——UVA 1584
- 章三例题1 UVA 272
- 章三例题2——UVA 10082
- 章三例题3——UVA 401 Palindromes
- 章三例题4——UVA 340 Master -Mind Hints
- 章三例题5——UVA 1583 Degit Generator
- 章三例题6——UVA 1584
- 章三例题1 UVA 272
- 章三例题2——UVA 10082
- 章三例题3——UVA 401 Palindromes
- 章三例题4——UVA 340 Master -Mind Hints
- 章三例题5——UVA 1583 Degit Generator
- 章三例题6——UVA 1584
- 章三例题1 UVA 272
- 章三例题2——UVA 10082
- 章三例题3——UVA 401 Palindromes