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>
#include <sstream>
using namespace std;
int sort(int a[],int n){
int temp;
for(int i=;i<n;i++){
for(int j=i;j<n;j++){
if(a[i]>a[j]){
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
return ;
}
int main(){
string num;
stringstream ss;
int size,j=;
cin>>num;
size=num.size();
int *a=new int[size];
int *b=new int[size+];
int *doubleNum=new int[size+];
for(int i=;i<size+;i++){
doubleNum[i]=;
b[i]=;
}
for(int i=;i<size;i++){
a[i]=num[i]-;
}
for(int i=size;i>;i--){
if(a[i-]+a[i-]>=){
doubleNum[i]+=(a[i-]+a[i-])%;
doubleNum[i-]+=;
}else{
doubleNum[i]+=a[i-]+a[i-];
}
}
if(doubleNum[]==){
for(int i=;i<size;i++){
b[i+]=doubleNum[i+];
}
sort(doubleNum,size+);
sort(a,size);
for(int i=;i<size;i++){
if(a[i]==doubleNum[i+]){
j++;
}
}
if(j==size){
cout<<"Yes"<<endl;
for(int i=;i<size;i++){
cout<<b[i+];
} }else{
cout<<"No"<<endl;
for(int i=;i<size;i++){
cout<<b[i+];
} }
}else{
cout<<"No"<<endl;
for(int i=;i<size+;i++){
cout<<doubleNum[i];
}
} }

测试

结果
 

数据结构练习 00-自测4. Have Fun with Numbers (20)的更多相关文章

  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. PAT-中国大学MOOC-陈越、何钦铭-数据结构基础习题集 00-自測4. Have Fun with Numbers (20) 【二星级】

    题目链接:http://www.patest.cn/contests/mooc-ds/00-%E8%87%AA%E6%B5%8B4 题面: 00-自測4. Have Fun with Numbers ...

  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. 00-自测4. Have Fun with Numbers

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

  5. PTA 自测-4 Have Fun with Numbers

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

  6. PTA数据结构 习题3.6 一元多项式的乘法与加法运算 (20分)

    一元多项式的乘法与加法运算 https://pintia.cn/problem-sets/434/problems/5865 设计函数分别求两个一元多项式的乘积与和. 时间限制:200 ms 内存限制 ...

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

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

  8. 压测:celey backend为rabbitmq pk redis

    使用celery的backend异步获取结果,本文使用rabbitmq 和 redis分别作为backend,代码对比如下 from celery import Celery, platforms i ...

  9. 华为CloudIDE免费公测,带你出坑带你飞

    你的代码仓库上线了吗?是不是有时候遇到这样的问题? 只想浏览一下代码,却发现线上浏览效果不佳,高亮显示什么的都没有.而在桌面端浏览要需要先同步代码,再用桌面端的IDE打开.尤其是使用git的时候,先要 ...

随机推荐

  1. VS扩展CodeMaid代码整理插件

    本文章转载:http://www.cnblogs.com/wintersun/p/3577039.html 官方地址:http://www.codemaid.net/ 开源VS扩展CodeMaid介绍 ...

  2. WindowsService的调试方法

    本人转载:http://www.cnblogs.com/xiebin1986/archive/2011/12/15/2288893.html 调试WindowsService,以前用过一个附加到进程的 ...

  3. 【AOS应用基础平台】完好了AOS标签库,和标准标签库完美兼容了

    [金码坊AOS开发平台]今天①完好了AOS标签库,和标准标签库完美兼容了.②新开发了依据子页面动态生成主页面的二级导航菜单功能.#AOS开发平台#

  4. PureMVC(JS版)源码解析(五):SimpleCommand类

          之前我们对PureMVC中涉及到观察者模式的三个基本类(Notification/Observer/Notifier)进行了分析,接下来将对PureMVC源码中的其他类进行分析,首先我们讲 ...

  5. Linux删除文件Argument list too long问题的解决方案

    方法一:使用find find . -name 文件 | xargs rm -f 但文件数量过多,find命令也会出现问题: -bash: /bin/find: Argument list too l ...

  6. css动画结束后 js无法修改translated值 .

    由于项目的需要,俺要做一些页面的转场动画. 即将是移动端,肯定是首先css动画了. 结果确发现,css动画中,如果设置animation-fill-mode: both;在动画结束后无法个性trans ...

  7. js--小结⑤

    js中的for循环,while循环,do...while循环和C语言的一模一样 有几个问题要提醒一下的是 1.  null是对象,即object       undefined是undefined d ...

  8. [配置文件] C#修改App.config,Web.config文件帮助类,ConfigHelper (转载)

    点击下载 ConfigHelper-sufei.rar 主要功能如下 .根据Key取Value值 .根据Key修改Value .添加新的Key ,Value键值对 .根据Key删除项 /// < ...

  9. struts2-ognl 访问静态方法

    在内网基本上还真没看到有哥们发现这个问题, 在google上有的哥们说 这是 v 2.3.20的一个bug, 有的人说在该版本中已经不建议通过ognl方式访问静态方法了. 对于这两种说法, 我比较赞同 ...

  10. mvc5 + ef6 + autofac搭建项目(四).1视屏上传生成截图

    即上一篇中上传涉及到的 一个视频生成截图的问题,这个很简单,这是上一篇中的代码片段 #region 视频上传,生成默认展示图片(自动剪切) try { string fileSavePath = Da ...