博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【UVA】 1583 --- Digit Generator
阅读量:2039 次
发布时间:2019-04-28

本文共 1352 字,大约阅读时间需要 4 分钟。

【UVA】 1583 --- Digit Generator

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’.
Sample Input
3
216
121
2005
Sample Output
198
0
1979

#include 
using namespace std;int main(){
int x[100050]{
0 }, y; for (int i = 1; i < 100050; i++) {
int m = i, n = i; while (m > 0) {
n += m % 10; m /= 10; } if (x[n] == 0) x[n] = i; } cin >> y; while (y--) {
int k; cin >> k; cout << x[k] << endl; } return 0;}

转载地址:http://mgyof.baihongyu.com/

你可能感兴趣的文章
Creating an Xcode4 Plugin
查看>>
iOS截取视频某一帧图片(关键帧,AVAssetImageGenerator)
查看>>
SDWebImage缓存图片的机制
查看>>
更轻量的 View Controllers
查看>>
谈谈编程思想
查看>>
iOS MapKit导航及地理转码辅助类
查看>>
检测iOS的网络可用性并打开网络设置
查看>>
简单封装FMDB操作sqlite的模板
查看>>
iOS开发中Instruments的用法
查看>>
iOS:关于获取网络类型和运营商信息
查看>>
使用CoreTelephony获得SIM卡网络运营商名称
查看>>
IOS学习笔记(六)inputAccessoryView,inputView
查看>>
LSCTableView: Building an Open, Drop-in Replacement of UITableView
查看>>
Android 假冒建行网银病毒分析
查看>>
9 Time-Saving iOS 7 Libraries
查看>>
11 Insanely Great iOS Developers Sites
查看>>
Core Telephony
查看>>
如何使用KeyChain保存和获取UDID
查看>>
Haskell教程
查看>>
Haskell 几乎无痛苦上手指南
查看>>