题目链接: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. php iconv 函数参数的区别

    本文同时发表在https://github.com/zhangyachen/zhangyachen.github.io/issues/57 用户输入:英特尔® 酷睿™ i7处理器大显身手 case1 ...

  2. xamarin android checkbox自定义样式

    xamarin android checkbox自定义样式 在drawable文件在新建checkbox_bg.xml文件 <?xml version="1.0" encod ...

  3. AntData.ORM框架 之 DotnetCore

    开源地址:https://github.com/yuzd/AntData.ORM   CodeGen使用请参考http://www.cnblogs.com/yudongdong/p/6421312.h ...

  4. 历年NOIP选题题解汇总

    联赛前上vijos板刷往年联赛题,使用在线编辑编写代码,祝我rp++. 废话不多说,挑比较有意思的记一下. 题目是按照年份排序的,最早只到了03年. 有些题目因为 我还没写/很早之前写的忘了 所以就没 ...

  5. jest for elasticsearch

    *elasticsearch(后面简称es) 背景: 目前项目应用中对es的操作用的是http(自己封装)的一套方法:有些数据处理起来还是需要定制开发处理,不是很方便.正好需要对本项目重新进行改造,于 ...

  6. PhoneGap开发环境搭建

    项目中要用PhoneGap开发,了解了下基本规则,记录一下,以备后查.(只针对Android平台) 一.安装 在安装PhoneGap开发环境之前,需要先安装以下框架: 1.Java SDK 2.Ecl ...

  7. [编织消息框架][传输协议]sctp

    OSI(Open System Interconnect),即开放式系统互联. 一般都叫OSI参考模型,是ISO(国际标准化组织)组织在1985年研究的网络互联模型. 该体系结构标准定义了网络互连的七 ...

  8. Parallels Desktop 12

    我微新solq123987654 备注:PD 科普:PD12有什么用,PD是让mac系统可以运行wind系统的软件,如果你不习惯mac os 或工作需要那PD绝对是个好软件正版要七八百授权,只要十五就 ...

  9. 微信小程序红包开发 小程序发红包 开发过程中遇到的坑 微信小程序红包接口的

    最近公司在开发一个小程序红包系统,客户抢到红包需要提现.也就是通过小程序来给用户发红包. 小程序如何来发红包呢?于是我想到两个方法. 之前公众号开发一直用了的.一个是红包接口,一个是企业支付接口.一开 ...

  10. Python day 3 (3)

    一:判断语句: 1  if 语句 : 2  或者if 语句 : else : 3  或者if 语句 : elif 语句 : else : 4注意:的使用,缩进一般用4个空格来完成. 二:input 语 ...