数据结构练习 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, 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:
1234567899Sample 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)的更多相关文章
- pat00-自测4. Have Fun with Numbers (20)
00-自测4. Have Fun with Numbers (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yu ...
- 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 ...
- 自测-4 Have Fun with Numbers
Notice that the number 123456789 is a 9-digit number consisting exactly the numbers from 1 to 9, wit ...
- 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 ...
- PTA 自测-4 Have Fun with Numbers
#include<iostream> #include<string> #include<cstring> #include<vector> using ...
- PTA数据结构 习题3.6 一元多项式的乘法与加法运算 (20分)
一元多项式的乘法与加法运算 https://pintia.cn/problem-sets/434/problems/5865 设计函数分别求两个一元多项式的乘积与和. 时间限制:200 ms 内存限制 ...
- PAT自测_打印沙漏、素数对猜想、数组元素循环右移、数字加倍重排、机器洗牌
-自测1. 打印沙漏() 本题要求你写个程序把给定的符号打印成沙漏的形状.例如给定17个“*”,要求按下列格式打印 ***** *** * *** ***** 所谓“沙漏形状”,是指每行输出奇数个符号 ...
- 压测:celey backend为rabbitmq pk redis
使用celery的backend异步获取结果,本文使用rabbitmq 和 redis分别作为backend,代码对比如下 from celery import Celery, platforms i ...
- 华为CloudIDE免费公测,带你出坑带你飞
你的代码仓库上线了吗?是不是有时候遇到这样的问题? 只想浏览一下代码,却发现线上浏览效果不佳,高亮显示什么的都没有.而在桌面端浏览要需要先同步代码,再用桌面端的IDE打开.尤其是使用git的时候,先要 ...
随机推荐
- 显示、隐藏 PowerShell
以下是一个快速实现该需求的 module.只要将以下代码复制粘贴到 Documents\WindowsPowerShell\Packages\PowerShell\PowerShell.psm1 即可 ...
- java多线程样例
这里我们做一个完整的样例来说明线程产生的方式不同而生成的线程的差别: package debug; import java.io.*;import java.lang.Thread; class My ...
- Android ListView实现仿iPhone实现左滑删除按钮
需要自定义ListView.这里就交FloatDelListView吧. 复写onTouchEvent方法.如下: @Override public boolean onTouchEvent(Moti ...
- ubuntu 14.04/15.10 安装基于eclipse的android app开发环境
一开始是装了ubuntu15.10,不知道是我的x200机器太old还是iso镜像有问题,总是各种莫名的引导不起来.有时候刚刚装好的干净系统,只install了一个vim和openssh,重启,然后就 ...
- Go语言学习资料汇总
网站: Go语言官网(访问)(中文镜像) Go语言中文网(访问) Go编译器(访问) Go语言中国社区(访问) golanghome(访问) GoLang中国(访问) Gopher Academic( ...
- android获取Mac地址和IP地址
获取Mac地址实际项目中测试了如下几种方法:(1)设备开通Wifi连接,获取到网卡的MAC地址(但是不开通wifi,这种方法获取不到Mac地址,这种方法也是网络上使用的最多的方法) //根据Wifi信 ...
- like的性能问题
使用like'%匹配的文字%',无法优化,因为索引起不到作用. 不过like'匹配的文字%',索引起作用.
- guid 新建
var guid = Guid.NewGuid();foreach (var i in new string[] { "P", "N", "B&quo ...
- (转)Hibernate 的应用(Hibernate 的结构)?
//首先获得 SessionFactory 的对象 SessionFactory sessionFactory = new Configuration().configure(). buildSess ...
- Java 文件下载
public HttpServletResponse download(String path, HttpServletResponse response) { try { // path是指欲下载的 ...
