Digit Generator(水)
题目链接: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 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(水)的更多相关文章
- UVa 1583 Digit Generator --- 水题+打表
UVa 1583 题目大意:如果x加上x的各个数字之和得到y,那么称x是y的生成元. 给定数字n,求它的最小生成元 解题思路:可以利用打表的方法,提前计算出以i为生成元的数,设为d,并保存在a[d]中 ...
- UVa 1225 Digit Counting --- 水题
UVa 1225 题目大意:把前n(n<=10000)个整数顺次写在一起,12345678910111213...,数一数0-9各出现多少字 解题思路:用一个cnt数组记录0-9这10个数字出现 ...
- [C++]最小生成元 (Digit Generator, ACM/ICPC Seoul 2005, UVa1583)
Question 例题3-5 最小生成元 (Digit Generator, ACM/ICPC Seoul 2005, UVa1583) 如果x+x的各个数字之和得到y,就是说x是y的生成元.给出n( ...
- 水题-------判断Digit Generator
题目链接:https://vjudge.net/problem/UVA-1583 题意:给出一个数N,判断最小的数x使x+(x各位数字的和)=N 题解:这是一个暴力求解题,不过有技巧,x各位数字的和最 ...
- 【UVA 1583】Digit Generator
题 题意 a加上 a的各位数=b,则b是a的digitSum,a是b的generator,现在给你digitSum,让你求它的最小的generator. 分析 一种方法是: 预处理打表,也就是把1到1 ...
- UVa 1583 Digit Generator(数学)
题意 假设a加上a全部数位上的数等于b时 a称为b的generator 求给定数的最小generator 给的数n是小于100,000的 考虑到全部数位和最大的数99,999的数位和也才45 ...
- UVa1583 Digit Generator
#include <stdio.h> int main(){ int T, N, i, k, digitsum, generator; scanf("%d" ...
- 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 ...
- 生成元(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 ...
随机推荐
- Java 伙伴系统(模拟)
参考:https://labrick.cc/2015/10/12/buddy-system-algorithm/ 代码过烂 不宜参考. output: [operating.entity.Heap@4 ...
- mysql5.7-Group Replication
什么是Group Replication 基于组的复制(Group-based Replication)是一种被使用在容错系统中的技术.Replication-group(复制组)是由能够相互通信的多 ...
- ES6 对象的扩展(下)
属性的可枚举性 对象的每个属性都有一个描述对象(Descriptor),用来控制该属性的行为.Object.getOwnPropertyDescriptor方法可以获取该属性的描述对象. var ob ...
- admin
执行顺序 : Admin 执行admin.py,导入models 第一次进来的时候,先创建admin.site对象(如果下次再有引入,不会重新创建) 拿到对象后执行该对象下的register()方法 ...
- Lucene.net(4.8.0) 学习问题记录三: 索引的创建 IndexWriter 和索引速度的优化
前言:目前自己在做使用Lucene.net和PanGu分词实现全文检索的工作,不过自己是把别人做好的项目进行迁移.因为项目整体要迁移到ASP.NET Core 2.0版本,而Lucene使用的版本是3 ...
- vue2 vue-router 组装
适用于vue cli搭建的项目 vue-router模块下载及记录到package.json中: npm i vue-router -D main.js中: import VueRouter from ...
- Xposed hook布局类资源文件的获取
如题,可以hook状态栏,为系统状态栏添加一个TextView @Override public void handleInitPackageResources(XC_InitPackageResou ...
- SourceTree管理工具的一些使用总结
一.冲突解决 在团队合作中,如果两个人同时修改一个文件 ,这个时候如果合并他人提交的代码是会产生冲突的,怎么解决? 1.先将代码提交至本地服务器 2.合并他人代码,这个时候在工作副本中会显示我们冲突的 ...
- jBPM学习之部署流程定义
也许部署流程定义的方法有很多,这里选用的是用Java代码调用工作流引擎提供的部署服务API.在这之前,假设你的Eclipse已经安装好了GPD工作流画图工具,并且学会了画出最简单的HelloWorld ...
- 摸索出来的chrom调试前后台数据(Java&&Ajax)交互的方法分享一下咯!!!
1:开始没想分享的,后来看到有大佬分享如何使用Chrom的工具进行调试,哈哈哈哼,我就借着他的博客写一下我摸索的如何进行前后台数据交互吧(注:反正是自己瞎 捣鼓出来的,也许适合我,and我脑补一下吧, ...