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. java 接口方法超时异常处理 设置超时时间

    原文:https://blog.csdn.net/coding_1994/article/details/87728374 使用线程池另起一个线程,可以使用  newFixedThreadPool() ...

  2. winform中使用缓存

    文章:Winform里面的缓存使用 另外一篇文章:缓存-MemoryCache Class

  3. Android.mk走读与Cmake配置

    Android.mk认识: 在上一次[https://www.cnblogs.com/webor2006/p/9946061.html]中学会了用NDK提供的交叉编译工程编译成Android能运行的可 ...

  4. python中常用的九种预处理方法

    本文总结的是我们大家在python中常见的数据预处理方法,以下通过sklearn的preprocessing模块来介绍; 1. 标准化(Standardization or Mean Removal ...

  5. es6 知识点总结(模块化 异步)

    问题: 什么是单线程和异步有什么关系? 什么是 event-loop 是否用过 jquery的deferred promise的基本使用和原理 介绍一下 async/await(和Promise 的区 ...

  6. [转载]Appium工作原理

    [Appium]Appium工作原理 2017-09-13 15:28 sophia194910 阅读(7658) 评论(0) 编辑 收藏 参考:http://www.cnblogs.com/zhjs ...

  7. 详解es6中Proxy代理对象的作用

    在es6中新添加了Proxy,那么它有什么作用啊?Proxy本意为代理,而es6中的Proxy也就是代理对象,那么代理对象感觉听起来很模糊,在这里就解释一下Proxy代理对象的作用. Proxy的主要 ...

  8. Ubuntu Linux虚拟机与windows快速创建共享文件夹

    有时候我们需要在windows下与远程Linux服务器传输文件,之前使用pscp传输文件很方便,但不方便传输多文件,同时也不便于查看.看了网上的教程总结创建共享文件夹的流程: 1.首先在本地windo ...

  9. node 初级概念总结

    (1)nodejs跳过了服务器软件 直接充当web服务器,nodejs也没有Web容器 (2)nodejs --- 自身哲学---[花最小的硬件成本,追求更好的并发请求,更高的处理性能] (3)nod ...

  10. 03_mysql-python模块, linux环境下python2,python3的

    ---恢复内容开始--- 1.Python2 正常 [root@IP ~]# pip install mysql-python DEPRECATION: Python 2.7 will reach t ...