数据结构练习 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的时候,先要 ...
随机推荐
- 【转】java.lang.StackOverflowError
http://blog.csdn.net/g19920917/article/details/8765638 出现一个java.lang.StackOverflowError异常.弄了半天,又是问高手 ...
- 用JAX-WS在Tomcat中公布WebService
JDK中已经内置了Webservice公布,只是要用Tomcat等Webserver公布WebService,还须要用第三方Webservice框架. Axis2和CXF是眼下最流行的Webservi ...
- 包的定义和导入-----package
1.包的定义 其中: . 表示当前路径 2.包的导入 一个类需要被外包访问的话,需要定义为public class. package org.lxh.demo08.a ; public class ...
- [D3] 5 .rangeBands
# d3.max ```js var xScale = d3.scale.ordinal() .domain(dataset) .rangeBands([0,w],0.3, 0.1);``` ### ...
- Java高级--Java线程运行栈信息的获取 getStackTrace()
我们在Java程序中使用日志功能(JDK Log或者Log4J)的时候,会发现Log系统会自动帮我们打印出丰富的信息,格式一般如下:为了免去解析StackTrace字符串的麻烦,JDK1.4引入了一个 ...
- Load resources from classpath in Java--reference
In general classpath is the path where JVM can find .class files and resources of your application a ...
- linux 安装软件的地方
用下边这个命令:mysqladmin -u root -p variables root是你的数据库帐号回车后会提示你输入密码,输入上边填写的帐号对应的密码 回车后出来一个大表,找到datadir这一 ...
- Linux学习笔记总结--云服务器挂载磁盘
1.通过 "fdisk -l" 命令查看 若执行fdisk -l命令,发现没有 /dev/xvdb 表明云服务无数据盘 2. 对数据盘进行分区 执行"fdisk /de ...
- 让图片在DIV中垂直居中
window.onload=function(){ var img = document.getElementById("imgdiv"); var div = document. ...
- SpringMVC注解@RequestMapping
/** * GET 查询 * * @return 视图路径 */ @RequestMapping(value = {"/index&q ...
