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. svn 上传 过滤

    代码上传过程中发现.so文件不能上传,查了一下,发现是svn服务器要设置上传过滤:很多文件,会被过滤掉,不能正常上传.设置如下: 通过终端打开配置文件: open ~/.subversion/conf ...

  2. 用高德地图API 通过详细地址获得经纬度

    http://cloud.sinyway.com/Service/amap.html http://restapi.amap.com/v3/geocode/geo?key=xxxxxxxxxxxxxx ...

  3. 关于编译Lambda时报告返回的为void的错误

    这个错误的信息是这样的: a lambda that has been specified to have a void return type cannot return a value 报告错误的 ...

  4. phpcms 换域名

    修改/caches/configs/system.php里面所有和域名有关的,把以前的老域名修改为新域名就可以了. 进行后台设置->站点管理   对相应的站点的域名进行修改. 更新系统缓存.点击 ...

  5. JSON 学习总结 <一>:什么是JSON

    JSON的相关资料和博客很多,JSON无处不用,最近项目中一直要用到JSON,今天没有加班,就写下,算是对自己的总结,对JSON又一次深入的认识. 废话不多了,直接进入今天的主题: 如题:今天就介绍下 ...

  6. 【转】Java中equals和==的区别

    [转]Java中equals和==的区别 java中的数据类型,可分为两类: 1.基本数据类型,也称原始数据类型.byte,short,char,int,long,float,double,boole ...

  7. [日历] C#修改CNDate日历帮助类 (转载)

    点击下载 CNDate.rar 主要功能如下 .传回公历y年m月的总天数 .根据日期值获得周一的日期 .获取农历 #region 私有方法 private static long[] lunarInf ...

  8. [弹出消息] C#MessageBox帮助类 (转载)

    点击下载 MessageBox.rar 主要功能如下所示1.显示消息提示对话框 2.控件点击 消息确认提示框 3.显示消息提示对话框,并进行页面跳转 4.输出自定义脚本信息 /// <summa ...

  9. java的集合框架之一

    java是一套很成熟的东西,很多商用的东西都喜欢用它,用的人多,稳定.不过一般也不怎么说起它,因为太常见了,私下里说,写java应用层得就像农民工,每一处都是搭积木,根据设计师的东西如何优雅地搭好积木 ...

  10. android--HttpURLConnection(转载)

    android之HttpURLConnection 1.HttpURLConnection连接URL1)创建一个URL对象 URL url = new URL(http://www.baidu.com ...