00-自测4. Have Fun with Numbers
Notice that the number 123456789 is a 9-digit number consisting exactly the numbers from 1 to 9, with no duplication. Double it we will obtain 246913578, which happens to be another 9-digit number consisting exactly the numbers from 1 to 9, only in a different permutation. Check to see the result if we double it again!
Now you are suppose to check if there are more numbers with this property. That is, double a given number with k digits, you are to tell if the resulting number consists of only a permutation of the digits in the original number.
Input Specification:
Each input file contains one test case. Each case contains one positive integer with no more than 20 digits.
Output Specification:
For each test case, first print in a line "Yes" if doubling the input number gives a number that consists of only a permutation of the digits in the original number, or "No" if not. Then in the next line, print the doubled number.
Sample Input:
1234567899
Sample Output:
Yes
2469135798
#include<iostream>
#include<string>
using namespace std;
int main() {
int i = ;
int j = ;
int len;
int temp;
string num;
//判断是否为输入的副本
bool is_dup = true;
int judge[];
//保存输出结果
int result[];
//保存进位
int counter[]; cin >> num;
len = num.length(); for (i = ; i < ; i++) {
counter[i] = ;
judge[i] = ;
}
//计算输出结果
for (i = len - ; i >= ; i--) {
temp = (num[i] - '');
judge[temp]++;
temp = temp * + counter[i];
result[j++] = temp % ;
if (i != )
counter[i - ] = temp / ;
else {
result[j++] = temp / ;
}
}
if (result[j - ] != )
len = j; for (i = ; i < len; i++) {
judge[result[i]]--;
} for (i = ; i < ; i++) {
if (judge[i] != ) {
is_dup = false;
}
} if (is_dup)
cout << "Yes" << endl;
else
cout << "No" << endl; for (j = len - ; j >= ; j--) {
cout << result[j];
}
return ;
}
00-自测4. Have Fun with Numbers的更多相关文章
- pat00-自测4. Have Fun with Numbers (20)
00-自测4. Have Fun with Numbers (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yu ...
- 数据结构练习 00-自测4. Have Fun with Numbers (20)
Notice that the number 123456789 is a 9-digit number consisting exactly the numbers from 1 to 9, wit ...
- 自测-4 Have Fun with Numbers
Notice that the number 123456789 is a 9-digit number consisting exactly the numbers from 1 to 9, wit ...
- PTA 自测-4 Have Fun with Numbers
#include<iostream> #include<string> #include<cstring> #include<vector> using ...
- PAT自测_打印沙漏、素数对猜想、数组元素循环右移、数字加倍重排、机器洗牌
-自测1. 打印沙漏() 本题要求你写个程序把给定的符号打印成沙漏的形状.例如给定17个“*”,要求按下列格式打印 ***** *** * *** ***** 所谓“沙漏形状”,是指每行输出奇数个符号 ...
- LC 357. Count Numbers with Unique Digits
Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n. Examp ...
- Using the Task Parallel Library (TPL) for Events
Using the Task Parallel Library (TPL) for Events The parallel tasks library was introduced with the ...
- JavaScript+svg绘制的一个动态时钟
结果图: 代码如下: <!DOCTYPE html> <html> <head> <title>动态时钟</title> </head ...
- WeQuant交易策略—NATR
策略名称:NATR策略关键词:规范真实波幅.价格突破. NATR,是对ATR指标进行了标准化.主要应用于了解价格的震荡幅度和节奏,在窄幅整理行情中用于寻找突破时机.本策略在当前价格高于之前价格一定倍数 ...
随机推荐
- MATLAB小波包的分解与重构
该文章用来直观上先感受一下小波包的分解与重构 例1 有一个信号,变量名为wave,随便找一个信号load进来就行了. t=wpdec(wave,3,'dmey'); t2 = wpjoin(t,[ ...
- HDU 4638 Group(莫队)题解
题意:n个数,每个数有一个值,每次询问一个区间,问你这个区间能分成连续的几段(比如7 1 2 8 就是两端 1 2 和 7 8) 思路:莫队.因为L.R移动顺序wa了20发...问了一下别人,都是先扩 ...
- 【做题】agc003E - Sequential operations on Sequence——经典结论
题意:有一个序列,初始是从\(1\)到\(n\)的\(n\)个数.有\(q\)次操作,每次操作给出\(q_i\),把当前的序列重复无数遍,然后截取最前面的\(q_i\)个元素作为新序列.要求输出完成所 ...
- 【做题】CF239E. k-d-sequence——线段树
首先,容易得到判断一个子串为"good k-d sequence"的方法: 子串中没有重复元素,且所有元素模d相等. 记mx为除以d的最大值,mn为除以d的最小值,则\(mx-mn ...
- Asp.net MVC 控制器ActionResult的例子
ActionResult 父类型 ViewResult View() 多重载应用 PartialViewResult PartialView() 部分试图 New EmptyResult() 空 如 ...
- Joint Detection and Identification Feature Learning for Person Search
Joint Detection and Identification Feature Learning for Person Search 2018-06-02 本文的贡献主要体现在: 提出一种联合的 ...
- (转) Dissecting Reinforcement Learning-Part.2
Dissecting Reinforcement Learning-Part.2 Jan 15, 2017 • Massimiliano Patacchiola 原文链接:https://mpatac ...
- Eclipse卸载插件SpringSoource-tool-suite
Eclipse卸载插件SpringSoource-tool-suite **系统环境:**Mac OS X 引子: 一直在纠结的一个问题,就是Eclipse开发java 项目在配置了InternalR ...
- Bootstrap 3 媒体查询
可以参考 Bootstrap 的媒体查询,写网站. html: <div class="bootstrap-3-media"> <p>Mobile-Fir ...
- HTML基本内容
设置背景色:<body bgcolor="#AAAAAA">,设置背景图:<body background="1.png">. 颜色的知 ...