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

解题思路:
  给定一个数,乘以2之后,各个数位的出现次数,是否与乘之前是否相同,相同输出Yes,否认输出No,然后下一行打印出乘2之后的各个数位。
  这个题目是属于超大数运算的类型,题目给出的最高数位是20位,那么即便是用最高的unsigned long long 也会面临溢出的情况,所以输入和输出,只能用string,诸位乘2,然后再记录每一位出现的次数,相比较就行。

大数乘法!全排列的意思是:各个数字出现的次数分别相同!

AC代码:

#include<bits/stdc++.h>
using namespace std;
char a[];
char b[];
int ori[];
int ne[];
int main(){
memset(ori,,sizeof(ori));
memset(ne,,sizeof(ne));
cin>>a;
//先反着放
int l=strlen(a);
for(int i=l-;i>=;i--){
b[l-i]=a[i];
ori[a[i]-'']++;
}
//大数乘法
int x=;
for(int i=;i<=l;i++){
int y=b[i]-'';
y*=;y+=x;
b[i]=y%+'';
x=y/;
ne[b[i]-'']++;
}
int l2=l;
if(x!=){
l2++;
b[l2]=x+'';
ne[b[l2]-'']++;
}
//判断
int f=;
for(int i=;i<=;i++){
if(ne[i]!=ori[i]){
f=;
break;
}
}
if(f){
cout<<"Yes"<<endl;
}else{
cout<<"No"<<endl;
}
for(int i=l2;i>=;i--){
cout<<b[i];
}
return ;
}
 

PAT 甲级 1023 Have Fun with Numbers (20 分)(permutation是全排列题目没读懂)的更多相关文章

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

  2. 1023 Have Fun with Numbers (20 分)

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

  3. PAT甲级:1136 A Delayed Palindrome (20分)

    PAT甲级:1136 A Delayed Palindrome (20分) 题干 Look-and-say sequence is a sequence of integers as the foll ...

  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 甲级 1054 The Dominant Color (20 分)

    1054 The Dominant Color (20 分) Behind the scenes in the computer's memory, color is always talked ab ...

  6. PAT 甲级 1027 Colors in Mars (20 分)

    1027 Colors in Mars (20 分) People in Mars represent the colors in their computers in a similar way a ...

  7. PAT 甲级 1005 Spell It Right (20 分)

    1005 Spell It Right (20 分) Given a non-negative integer N, your task is to compute the sum of all th ...

  8. PAT 甲级 1058 A+B in Hogwarts (20 分) (简单题)

    1058 A+B in Hogwarts (20 分)   If you are a fan of Harry Potter, you would know the world of magic ha ...

  9. PAT 甲级 1031 Hello World for U (20 分)(一开始没看懂题意)

    1031 Hello World for U (20 分)   Given any string of N (≥) characters, you are asked to form the char ...

随机推荐

  1. python django uwsgi nginx安装

    python django uwsgi nginx安装 已安装完成python/django的情况下安装 pip install uwsgi cd /usr/share/nginx/html/ vim ...

  2. PHP 调用 exec 执行中文命令的坑

    服务器系统Linux通过php exec 执行rar x 解压命令 保持目录结构,压缩包内英文目录正常解压中文目录解压失败,请问有什么办法可以解决直接在终端命令进行解压是没有问题的 最终解决办法 $s ...

  3. inux中查看各文件夹大小命令:du -h --max-depth=1

    du [-abcDhHklmsSx] [-L <符号连接>][-X <文件>][--block-size][--exclude=<目录或文件>] [--max-de ...

  4. H5:加载原理,慢加载和卡顿原因分析,

    前端H5工作原理: 请求和显示原理 H5页面卡顿原因分析: 1.动画太多:渲染重绘占用GPU 2.页面操作导致重绘频繁 3.页面元素复杂:资源类标签太多(图像/视频/dom树太长) 4.内置webvi ...

  5. [转载]深入理解Java垃圾回收机制

    深入理解Java垃圾回收机制 2016-07-28 20:07:49 湖冰2019 阅读数 14607更多 分类专栏: JAVA基础   原文:http://www.linuxidc.com/Linu ...

  6. postgresql backup

    #!/bin/sh # Database backup script # Backup use postgres pg_dump command: # pg_dump -U <user> ...

  7. SSH自动断开处理

    解决ssh登录后闲置时间过长而断开连接 时我们通过终端连接服务器时,当鼠标和键盘长时间不操作,服务器就会自动断开连接,我们还的需要重新连接,感觉很麻烦,总结一下解决此问题的方法 方法一. 修改/etc ...

  8. AbstractWrapper ,EntityWrapper, QueryWrapper, UpdateWrappe

    https://blog.csdn.net/qq_42112846/article/details/88086035 https://blog.csdn.net/m0_37034294/article ...

  9. 数据结构实验之图论一:基于邻接矩阵的广度优先搜索遍历 (SDUT 2141)

    #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> ...

  10. HDOJ->考新郎(sdut1021)

    考新郎 Problem Description 在一场盛大的集体婚礼中,为了使婚礼进行的丰富一些,司仪临时想出了有一个有意思的节目,叫做"考新郎",具体的操作是这样的: 首先,给每 ...