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. mysql 创建用户并授权数据库

    create user test identified by ‘password’:password  你要创建的用户对应的密码 grant all on database.*  to  test;  ...

  2. 快看,那个学SLAM 的崩溃了!

    点"计算机视觉life"关注,置顶更快接收消息! 本文列举了当前优秀SLAM方案,点出了SLAM学习者的困境,最后打算搞点大事 请把此文转发给你认识的SLAM大神,愿你头发浓密,心 ...

  3. Centos杀死进程kill方法大全

    杀死进程最安全的方法是单纯使用kill命令. 首先使用ps -ef命令确定要杀死进程的PID,然后输入以下命令: # kill -pid 注释:标准的kill命令通常都能达到目的.终止有问题的进程,并 ...

  4. iar8.32版本关于cmsis的说明

    平台是cubemx5.3 keil5.26 带freertos,使用iar8.32,在上图中的use cmsis 打勾与否都能编译通过.

  5. Fibonacci数性质

    Fibonacci数性质 0.\(F_{n-1}+F_{n-2}=F_{n} ,特殊的 F_{0}=1,F_{1}=1\) 上述式子为定义式 1.\(F_{0}+F_{1}+...+F_{n}=F_{ ...

  6. C# 可观察集合

    static void Main() { var data = new ObservableCollection<string>(); data.CollectionChanged += ...

  7. 关于npm audit fix

    https://blog.csdn.net/weixin_40817115/article/details/81007774 npm audit : npm@5.10.0 & npm@6,允许 ...

  8. Codeforces Round #583 (Div. 1 + Div. 2, based on Olympiad of Metropolises) A题

    A. Optimal Currency ExchangeAndrew was very excited to participate in Olympiad of Metropolises. Days ...

  9. PHP mysqli_commit() 函数

    关闭自动提交,做一些查询,然后提交查询: <?php // 假定数据库用户名:root,密码:123456,数据库:RUNOOB $con=mysqli_connect("localh ...

  10. vue 中 v-model

    一.v-model: 先上段简单的 vue 代码: // 定义 v-model 示例组件 Vue.component('bindData', { template:` <div> < ...