题目链接:http://acm.tju.edu.cn/toj/showp2502.html2502.   Digit Generator


Time Limit: 1.0 Seconds   Memory Limit: 65536K
Total Runs: 2426   Accepted Runs: 1579

For a positive integer N, the digit-sum of N is defined as the sum of N itself and its digits. When M is the digitsum of N, we call N a generator of M.

For example, the digit-sum of 245 is 256 (= 245 + 2 + 4 + 5). Therefore, 245 is a generator of 256.

Not surprisingly, some numbers do not have any generators and some numbers have more than one generator. For example, the generators of 216 are 198 and 207.

You are to write a program to find the smallest generator of the given integer.

Input

Your program is to read from standard input. The input consists of T test cases. The number of test cases T is given in the first line of the input. Each test case takes one line containing an integer N, 1 ≤ N ≤ 100,000.

Output

Your program is to write to standard output. Print exactly one line for each test case. The line is to contain a generator of N for each test case. If N has multiple generators, print the smallest. If N does not have any generators, print 0.

The following shows sample input and output for three test cases.

Sample Input

3
216
121
2005

Output for the Sample Input

198
0
1979
数组应用水题直接给代码:
 #include<cstdio>
#include<cstring>
#include<string>
using namespace std;
int main()
{
char num[];
int T;
scanf("%d",&T);
while(T--)
{
scanf("%s",num);
int tm = *strlen(num);
int sum =num[]-'';
for(int i = ;i < strlen(num) ;i++)
{
sum*=;
sum+=(num[i]-'');
}
int tt = sum - tm;
int i;
for( i = tt ; i < sum ; i++)
{
int ga = i;
int flag = ;
while(ga > )
{
flag+=ga%;
ga = ga/;
}
if((i+flag)==sum)
{
printf("%d\n",i);
break;
}
}
if(i==sum) puts("");
}
return ;
}

Digit Generator(水)的更多相关文章

  1. UVa 1583 Digit Generator --- 水题+打表

    UVa 1583 题目大意:如果x加上x的各个数字之和得到y,那么称x是y的生成元. 给定数字n,求它的最小生成元 解题思路:可以利用打表的方法,提前计算出以i为生成元的数,设为d,并保存在a[d]中 ...

  2. UVa 1225 Digit Counting --- 水题

    UVa 1225 题目大意:把前n(n<=10000)个整数顺次写在一起,12345678910111213...,数一数0-9各出现多少字 解题思路:用一个cnt数组记录0-9这10个数字出现 ...

  3. [C++]最小生成元 (Digit Generator, ACM/ICPC Seoul 2005, UVa1583)

    Question 例题3-5 最小生成元 (Digit Generator, ACM/ICPC Seoul 2005, UVa1583) 如果x+x的各个数字之和得到y,就是说x是y的生成元.给出n( ...

  4. 水题-------判断Digit Generator

    题目链接:https://vjudge.net/problem/UVA-1583 题意:给出一个数N,判断最小的数x使x+(x各位数字的和)=N 题解:这是一个暴力求解题,不过有技巧,x各位数字的和最 ...

  5. 【UVA 1583】Digit Generator

    题 题意 a加上 a的各位数=b,则b是a的digitSum,a是b的generator,现在给你digitSum,让你求它的最小的generator. 分析 一种方法是: 预处理打表,也就是把1到1 ...

  6. UVa 1583 Digit Generator(数学)

     题意 假设a加上a全部数位上的数等于b时 a称为b的generator  求给定数的最小generator 给的数n是小于100,000的  考虑到全部数位和最大的数99,999的数位和也才45 ...

  7. UVa1583 Digit Generator

    #include <stdio.h> int main(){    int T, N, i, k, digitsum, generator;    scanf("%d" ...

  8. Digit Generator UVA - 1583

    ​ For a positive integer N, the digit-sum of N is defined as the sum of N itself and its digits. Whe ...

  9. 生成元(Digit Generator ,ACM/ICPC Seoul 2005 ,UVa 1583)

    生成元:如果 x 加上 x 各个数字之和得到y,则说x是y的生成元. n(1<=n<=100000),求最小生成元,无解输出0. 例如:n=216 , 解是:198 198+1+9+8=2 ...

随机推荐

  1. 每周.NET前沿技术文章摘要(2017-05-24)

    汇总国外.NET社区相关文章,覆盖.NET ,ASP.NET等内容: .NET Free eBook/Guide on '.NET Microservices – Architecture for C ...

  2. C语言_第二讲_规范以及常用数据类型

    一丶编码规范基本数据类型 编码规范 任何程序员,都应该有良好的的编码习惯,便于以后的代码可读性和维护 常见了编码规范有 匈牙利命名法 驼峰式大小写 匈牙利命名法: 是电脑程序设计中的一种变量命名规则, ...

  3. 447. Number of Boomerangs

    Given n points in the plane that are all pairwise distinct, a "boomerang" is a tuple of po ...

  4. (一)基于阿里云的MQTT远程控制(Android 连接MQTT服务器,ESP8266连接MQTT服务器实现远程通信控制----简单的连接通信)

    如果不了解MQTT的可以看这篇文章  http://www.cnblogs.com/yangfengwu/p/7764667.html http://www.cnblogs.com/yangfengw ...

  5. 大白话Vue源码系列(05):运行时鸟瞰图

    阅读目录 Vue 实例的生命周期 实例创建 响应的数据绑定 挂载到 DOM 节点 结论 研究 runtime 一边 Vue 一边源码 初看 Vue 是 Vue 源码是源码 再看 Vue 不是 Vue ...

  6. express整合webpack的打包文件dist

    对于我来说,第一次接触前后端整合问题的小白,刚开始是一脸懵逼,这个问题整整坑了我一个晚上加一个早上,现在写出来总结: 前端开发:vue-cli+webpack: 后台开发:nodejs框架expres ...

  7. javascript01

    手敲代码01 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <ti ...

  8. lesson - 1 - IP /DNS /cat !$ /putty 知识扩充

    一.知识点扩充 1.嵌入式Linux 开发与运维 .安卓手机  .     Linux真正的用武之地是蓬勃发展的信息接入设备市 场.这些新兴的设备只有有限的内存,价格也只有几百美元,因此开发者需要新的 ...

  9. POI 导出导入工具类介绍

    介绍: Apache POI是Apache软件基金会的开源项目,POI提供API给Java程序对Microsoft Office格式档案读和写的功能. .NET的开发人员则可以利用NPOI (POI ...

  10. 一点解决版本冲突的应急思路、怎样在所有jar包文件中搜索冲突的方法?

    maven是一个很好的项目管理工具,你可以轻松的定义一个引用,从而达到使用别人写好的库的作用.且maven可以轻松地和jenkins配合,从而使打包部署变得更容易. 但是也因为这样,我们变得更傻瓜了, ...