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. String、StringBuffer 的使用 ,两个面试问题

    1>统计不同类型字符个数 public static void main(String[] args) { //案例:统计不同类型字符个数 String password = "abZ ...

  2. MTP 写字机器

    目标 无意中看到下面视频,我打算也实现一个类似机器 视频.视频2.视频3 来源于油管Creativity Buzz的创意,顺便了解到有家AxiDraw公司在生产这种机器,淘宝上也有售卖. 想法 观看视 ...

  3. CPU指令集设计RISC和CISC

    CPU指令集 硬件实现具有速度快,成本高,灵活性差,软件实现与之相反.因此出现频率高的基本功能首选硬件实现.指令集的不同反映了设计原理.制造技术和系统类别. RISC 精简指令集计算机(Reduced ...

  4. javascript创建函数的20种方式汇总

    http://www.jb51.net/article/68285.htm 工作中常常会创建一个函数来解决一些需求问题,以下是个人在工作中总结出来的创建函数20种方式,你知道多少? function ...

  5. 1、Keepalived及VRRP原理介绍

    keepalived:即在linux中vrrp协议的实现 http://www.keepalived.org/ 什么是Keepalived?  Keepalived是一个用C语言编写的路由软件.该项目 ...

  6. 【BZOJ】3572: [Hnoi2014]世界树

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=3572 算是细节题了吧.. 构出虚树,考虑z正反DP两次求出虚树中每个点最近的议事处是哪一个 ...

  7. VMWare16安装windows7遇到的一些问题

    本人写这篇博客是为了记录了一些自己在使用VMware16安装Windows7时遇到的一些问题.本人使用的Windows7 ios镜像是小于4g的镜像. Windows7 ios的镜像地址为:https ...

  8. ZZNU 正约数之和 2094

    #include<iostream> #include<cstring> #include<queue> #include<cstdio> #inclu ...

  9. JNI手动释放内存(避免内存泄露)

    . 哪些需要手动释放? 不要手动释放(基本类型): jint , jlong , jchar 需要手动释放(引用类型,数组家族): jstring,jobject ,jobjectArray,jint ...

  10. dataway_代码规范

    无论何时无论何地,只要写代码,请遵从这样的规范. ----------------------------------------------------------------- css代码规范. ...