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的更多相关文章

  1. pat00-自测4. Have Fun with Numbers (20)

    00-自测4. Have Fun with Numbers (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yu ...

  2. 数据结构练习 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 ...

  3. 自测-4 Have Fun with Numbers

    Notice that the number 123456789 is a 9-digit number consisting exactly the numbers from 1 to 9, wit ...

  4. PTA 自测-4 Have Fun with Numbers

    #include<iostream> #include<string> #include<cstring> #include<vector> using ...

  5. PAT自测_打印沙漏、素数对猜想、数组元素循环右移、数字加倍重排、机器洗牌

    -自测1. 打印沙漏() 本题要求你写个程序把给定的符号打印成沙漏的形状.例如给定17个“*”,要求按下列格式打印 ***** *** * *** ***** 所谓“沙漏形状”,是指每行输出奇数个符号 ...

  6. 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 ...

  7. Using the Task Parallel Library (TPL) for Events

    Using the Task Parallel Library (TPL) for Events The parallel tasks library was introduced with the ...

  8. JavaScript+svg绘制的一个动态时钟

    结果图: 代码如下: <!DOCTYPE html> <html> <head> <title>动态时钟</title> </head ...

  9. WeQuant交易策略—NATR

    策略名称:NATR策略关键词:规范真实波幅.价格突破. NATR,是对ATR指标进行了标准化.主要应用于了解价格的震荡幅度和节奏,在窄幅整理行情中用于寻找突破时机.本策略在当前价格高于之前价格一定倍数 ...

随机推荐

  1. P2257 YY的GCD(莫比乌斯反演)

    第一次做莫比乌斯反演,推式子真是快乐的很啊(棒读) 前置 若函数\(F(n)\)和\(f(d)\)存在以下关系 \[ F(n)=\sum_{n|d}f(d) \] 则可以推出 \[ f(n)=\sum ...

  2. (转载)Unity里实现更换游戏对象材质球

    在unity中本来想实现在一个背景墙上更换图片的功能 在网上查了一些资料说是用Image,但我是新手小白刚接触Unity不久好多组建还不会用,就想能不能通过改变游戏对象的材质球来更换游戏对象的背景. ...

  3. POJ 3693 Maximum repetition substring(连续重复子串)

    http://poj.org/problem?id=3693 题意:给定一个字符串,求重复次数最多的连续重复子串. 思路: 这道题确实是搞了很久,首先枚举连续子串的长度L,那么子串肯定包含了r[k], ...

  4. Centos7安装配置Apache+PHP+Mysql+phpmyadmin

    转载自: Centos7安装配置Apache+PHP+Mysql+phpmyadmin 一.安装Apache yum install httpd 安装成功后,Apache操作命令: systemctl ...

  5. 正则获取 某段 DIV 中 的内容

    string html = "<div class='aa'><div class='left'>324324<div>dsfsdf</div> ...

  6. FILE,id不一致

    当图片全部是新增的时候,id和FILE一一对应,后台可以匹配处理. array(1) { ["banner_img"] => array(5) { ["name&q ...

  7. Python day2_int以及string的常见方法1_笔记

    Python中,主要的基本类型有:数字(int型).字符串(string型).列表(list型).元祖(tuple型).字典(direct型).布尔值(boolean型) 1.int型 1.强转int ...

  8. Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.3:compile

    完整的错误信息: [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.3:compile ( ...

  9. python+unittet在linux与windows使用的区别

    使用python的unittest编写单元测试框架,批量运行测试用例时,如果使用discover时,windows环境下和linux环境下的代码不一样 Windows环境的run.py代码: case ...

  10. ASP.NET中Page_Load()与Page_Init()的区别

    Page_Init()事件:aspx初始化时触发,只执行一次,常用于页面初始化,并且执行在page_load之前,如果在aspx的程序中需要使用该方法,那么该方法的类需要继承 System.Web.U ...