1023 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 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<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define maxnum 100005 int a[] = {};
int count1[] = {}; //分别对倍乘前后的位计数
int count2[] = {}; int main(){
string s;
cin >> s;
int len = s.size();
for(int i=;i < s.size();i++){
a[i] = s[i]-'';
}
for(int i=;i < len;i++){
count1[a[i]]++;
}
for(int i=;i < len/;i++){ //翻转
swap(a[i],a[len-i-]);
} int jinwei = ; //倍乘
for(int i=;i <= len;i++){
int num = a[i]* + jinwei;
a[i] = num%;
jinwei = (num)/;
} // for(auto num:a) cout << num << " "; int pos = ;
for(int i=;i >= ;i--){
if(a[i]){pos = i;break;}
}
for(int i=;i <= pos;i++){
count2[a[i]]++;
} int flag = ;
for(int i=;i < ;i++){
if(count1[i] != count2[i])flag = ;
}
if(flag) cout << "Yes" << endl;
else cout << "No" << endl; for(int i=pos;i >= ;i--){
cout << a[i];
} return ;
}

_

 

PAT 1023 Have Fun with Numbers的更多相关文章

  1. PAT 1023 Have Fun with Numbers[大数乘法][一般]

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

  2. pat 1023 Have Fun with Numbers(20 分)

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

  3. PAT (Advanced Level) Practice 1023 Have Fun with Numbers (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1023 Have Fun with Numbers (20 分) 凌宸1642 题目描述: Notice that the number ...

  4. PAT 甲级 1023 Have Fun with Numbers(20)(思路分析)

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

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

  6. 浙大 pat 1023题解

    1023. Have Fun with Numbers (20) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue ...

  7. 1023 Have Fun with Numbers (20 分)

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

  8. PAT 甲级 1023 Have Fun with Numbers

    https://pintia.cn/problem-sets/994805342720868352/problems/994805478658260992 Notice that the number ...

  9. PAT Advanced 1023 Have Fun with Numbers (20) [⼤整数运算]

    题目 Notice that the number 123456789 is a 9-digit number consisting exactly the numbers from 1 to 9, ...

随机推荐

  1. Anaconda使用命令

    参考的地址:https://zhuanlan.zhihu.com/p/32925500 conda 基础命令: 1.验证conda已被安装 conda --version 终端上就会以conda 版本 ...

  2. pom.xml中build标签

    1.分类 (1)全局配置(project build) 针对整个项目的所有情况都有效 (2)配置(profile build) 针对不同的profile配置 <project xmlns=&qu ...

  3. HDU 6249 Alice’s Stamps(dp)

    http://acm.hdu.edu.cn/showproblem.php?pid=6249 题意: 给出n个区间,求选k个区间的最大区间并. 思路: 可能存在左端点相同的多个区间,那么此时我们肯定选 ...

  4. HDU 6215 Brute Force Sorting(链表)

    http://acm.hdu.edu.cn/showproblem.php?pid=6215 题意:给出一个序列,对于每个数,它必须大于等于它前一个数,小于等于后一个数,如果不满足,就删去.然后继续去 ...

  5. JAVA读取CSV文件到MySQL数据库中

    maven项目pom配置: <dependency> <groupId>net.sourceforge.javacsv</groupId> <artifact ...

  6. 项目Alpha冲刺--3/10

    项目Alpha冲刺--3/10 1.团队信息 团队名称:基于云的胜利冲锋队 成员信息 队员学号 队员姓名 个人博客地址 备注 221500201 孙文慈 https://www.cnblogs.com ...

  7. _event_worldstate

    EventId 事件ID ID WorldStateUI.dbc第10列数字部分 StartValue 起始值 Entry 更新世界状态需要击杀生物或摧毁物体的entry,正数为生物,负数为物体 St ...

  8. Java问题解决:Java compiler level does not match the version of the installed Java project facet.

    问题原因:Java编译器级别与Facted Project 中的Java 版本设定不匹配. 解决办法:将两者设置一致 1.查看Java compiler level : 选中项目右键propertie ...

  9. Centos7 linux下通过源码安装redis以及使用

    下载redis安装包 wget http://download.redis.io/releases/redis-5.0.3.tar.gz 解压压缩包 tar -zxvf redis-.tar.gz y ...

  10. List、Map、Set的区别与联系

    重复和有序 List 存储的元素是有顺序的,并且值允许重复: Map 元素按键值对存储,无放入顺序 ,它的键是不允许重复的,但是值是允许重复的: Set 存储的元素是无顺序的,并且不允许重复,元素虽然 ...