00-自测4. Have Fun with Numbers (20)

时间限制
400 ms
内存限制
65536 kB
代码长度限制
8000 B
判题程序
Standard
作者
CHEN, Yue

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 <cstdio>
#include <cstring>
#include <string>
#include <queue>
#include <cmath>
#include <iostream>
using namespace std;
int ti[],num1[],num2[];
char num[];
int main(){
//freopen("D:\\INPUT.txt","r",stdin);
scanf("%s",num); //cout<<num<<endl; int i;
for(i=;i<strlen(num);i++){
num1[i]=num[i]-'';
ti[num1[i]]++;
num2[i]=*num1[i];
}
int k=,t;
for(i=strlen(num)-;i>=;i--){
t=num2[i]+k;
num2[i]=t%;
ti[num2[i]]--;
k=t/;
}
bool can=false;
if(!k){
for(i=;i<=;i++){
if(ti[i]){
break;
}
}
if(i==){
can=true;
}
}
if(can){
printf("Yes\n");
}
else{
printf("No\n");
}
if(k){
printf("%d",k);
}
for(i=;i<strlen(num);i++){
printf("%d",num2[i]);
}
printf("\n");
return ;
}

pat00-自测4. Have Fun with Numbers (20)的更多相关文章

  1. 数据结构练习 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, wit ...

  2. How to Pronounce Numbers 20 – 1 Billion

    How to Pronounce Numbers 20 – 1 Billion Share Tweet Share Tagged With: Numbers Numbers are something ...

  3. PAT甲级 1120. Friend Numbers (20)

    1120. Friend Numbers (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Two in ...

  4. pat1100. Mars Numbers (20)

    1100. Mars Numbers (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue People o ...

  5. pat1069. The Black Hole of Numbers (20)

    1069. The Black Hole of Numbers (20) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, ...

  6. 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 ...

  7. 1069. The Black Hole of Numbers (20)【模拟】——PAT (Advanced Level) Practise

    题目信息 1069. The Black Hole of Numbers (20) 时间限制100 ms 内存限制65536 kB 代码长度限制16000 B For any 4-digit inte ...

  8. PAT 甲级 1069 The Black Hole of Numbers (20 分)(内含别人string处理的精简代码)

    1069 The Black Hole of Numbers (20 分)   For any 4-digit integer except the ones with all the digits ...

  9. PAT 甲级 1023 Have Fun with Numbers (20 分)(permutation是全排列题目没读懂)

    1023 Have Fun with Numbers (20 分)   Notice that the number 123456789 is a 9-digit number consisting ...

随机推荐

  1. WPF的Image控件图片不能显示出来的问题探究

    在wpf项目中,用Image来显示资源图片,在界面是可以显示,但是在运行的时候却显示不出来. <Image Source=" HorizontalAlignment="Lef ...

  2. Kylin存储和查询的分片问题

    本文来自网易云社区 作者:汪胜 相关概念介绍 为了了解Kylin存储和查询的分片问题,需要先介绍两个重要概念:segment和cuboid.相信大数据行业的相关同学都不陌生.Kylin每次提交一个新的 ...

  3. ubuntu安装nginx与配置

    命令行安装:(当前时间为2018.11,版本为1.10.3) sudo apt-get install nginx 安装好的文件位置: /usr/sbin/nginx:主程序 /etc/nginx:存 ...

  4. 【转载】Java资源大全中文版

    Java资源大全中文版 我想很多程序员应该记得 GitHub 上有一个 Awesome - XXX 系列的资源整理.awesome-java 就是 akullpp 发起维护的 Java 资源列表,内容 ...

  5. Mysql导入数据时-data truncated for column..

    在导入Mysql数据库时,发现怎么也导入不进去数据,报错: 查看表定义结构:可以看到comm 定义类型为double类型 原来是因为数据库文件中: 7369    smith    clerk     ...

  6. 解决 Github用户名 变为 invalid-email-address 问题

    解决 Github用户名 变为 invalid-email-address 问题 If the identity used for this commit is wrong, you can fix ...

  7. Python实现KNN算法

    Python实现Knn算法 关键词:KNN.K-近邻(KNN)算法.欧氏距离.曼哈顿距离  KNN是通过测量不同特征值之间的距离进行分类.它的的思路是:如果一个样本在特征空间中的k个最相似(即特征空间 ...

  8. 条目四《用empty来代替检查size()是否为0》

    条目四<用empty来代替检查size()是否为0> 首先先说结论: empty()实现为内联函数.(众所周知, 优秀的内联函数的效率比一般函数是高的) 在stl标准库中,empty()对 ...

  9. QtLog

    QtLog #include "mainwindow.h" #include <QApplication> #include <QByteArray> #i ...

  10. Jmeter拓展插件可查看和lr一样的图形结果

    利用插件可通过图形直观查看CPU.Memory等的运行情况 1. JmeterPlugins.jar插件下载地址:http://jmeter-plugins.org/downloads/all 下载并 ...