博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
数据结构练习 00-自测4. Have Fun with Numbers (20)
阅读量:6849 次
发布时间:2019-06-26

本文共 1851 字,大约阅读时间需要 6 分钟。

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:

Yes2469135798
#include
#include
#include
using namespace std;int sort(int a[],int n){ int temp; for(int i=0;i
a[j]){ temp=a[i]; a[i]=a[j]; a[j]=temp; } } } return 0;}int main(){ string num; stringstream ss; int size,j=0; cin>>num; size=num.size(); int *a=new int[size]; int *b=new int[size+1]; int *doubleNum=new int[size+1]; for(int i=0;i
0;i--){ if(a[i-1]+a[i-1]>=10){ doubleNum[i]+=(a[i-1]+a[i-1])%10; doubleNum[i-1]+=1; }else{ doubleNum[i]+=a[i-1]+a[i-1]; } } if(doubleNum[0]==0){ for(int i=0;i
测试
结果
 
 

转载于:https://www.cnblogs.com/Zengineer/p/4315559.html

你可能感兴趣的文章
提高用户体验方式:饥饿营销
查看>>
Java8中的LocalDateTime工具类
查看>>
Exchange 2013 PowerShell创建自定义对象
查看>>
RAID-10 阵列的创建(软)
查看>>
javaScript的调试(四)
查看>>
nginx不使用正则表达式匹配
查看>>
利用putty进行vnc + ssh tunneling登录
查看>>
js重定向---实现页面跳转的几种方式
查看>>
hadoop1.x作业提交过程分析(源码分析第二篇)
查看>>
默认安装vsftpd后
查看>>
《Redis设计与实现》读书笔记
查看>>
waiting for changelog lock.
查看>>
小白学爬虫-批量部署Splash负载集群
查看>>
你离BAT之间,只差这一套Java面试题
查看>>
laravel package 推荐,数据备份
查看>>
Synchronized锁在Spring事务管理下,为啥还线程不安全?
查看>>
环境变量PATH cp命令 mv命令 文档查看cat/more/less/head/tail
查看>>
阿里云亮相2019联通合作伙伴大会,边缘计算等3款云产品助力5G时代产业数字化转型...
查看>>
dubbo源码分析-服务端发布流程-笔记
查看>>
阿里云发布Apsara SA系列混合云存储阵列
查看>>