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指标进行了标准化.主要应用于了解价格的震荡幅度和节奏,在窄幅整理行情中用于寻找突破时机.本策略在当前价格高于之前价格一定倍数 ...
随机推荐
- CPU指令集设计RISC和CISC
CPU指令集 硬件实现具有速度快,成本高,灵活性差,软件实现与之相反.因此出现频率高的基本功能首选硬件实现.指令集的不同反映了设计原理.制造技术和系统类别. RISC 精简指令集计算机(Reduced ...
- Git、GitHub、GitLab三者之间的联系以及区别
在讲区别以及联系之前先简要的介绍一下,这三者都是什么(本篇文章适合刚入门的新手,大佬请出门左转) 1.什么是 Git? Git 是一个版本控制系统. 版本控制是一种用于记录一个或多个文件内容变化,方便 ...
- Winform 设置控件值
private void SetControlValue(Control control, object value) { try { control.FindForm().Invoke((Actio ...
- 单域名下多子域名同时认证HTTPS
参考: http://blog.csdn.net/wzj0808/article/details/53401101 http://www.cnblogs.com/silin6/p/5931640.ht ...
- 3.3 idea中使用git遇到的一些问题
1. 修改TortoiseGit用户名和密码 修改TortoiseGit用户名和密码其实就是对Git的用户名和密码就行修改. 控制面板 -> 点击“用户账户” -> 管理windows凭据 ...
- [转][c++][跨平台]c++跨平台开发小结
转自:https://blog.csdn.net/dj0379/article/details/53577135 linux编程与windows编程的差异之处: 1. 文件与目录的大小写以及路径分隔符 ...
- 从RGB扫描图到数字化等高线矢量图
1 用arcgis 对地形图进行校正,主要是通过判断地图的坐标系统,然后将图层的坐标系统设置正确.选择图上的经纬网交点,对原图进行校正,一般要求四角和均匀布点. 2 二值化图像.如果是RGB图像,即彩 ...
- leecode第一百二十二题(买卖股票的最佳时机II)
class Solution { public: int maxProfit(vector<int>& prices) { int len=prices.size(); ) ; , ...
- download 属性
1.使用场景 对浏览器 识别/不识别 的文件下载 2.核心代码 var eleTextarea = document.querySelector('textarea'); var eleButton ...
- JNI手动释放内存(避免内存泄露)
. 哪些需要手动释放? 不要手动释放(基本类型): jint , jlong , jchar 需要手动释放(引用类型,数组家族): jstring,jobject ,jobjectArray,jint ...