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 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是全排列题目没读懂)的更多相关文章
- 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 ...
- 1023 Have Fun with Numbers (20 分)
1023 Have Fun with Numbers (20 分) Notice that the number 123456789 is a 9-digit number consisting ...
- PAT甲级:1136 A Delayed Palindrome (20分)
PAT甲级:1136 A Delayed Palindrome (20分) 题干 Look-and-say sequence is a sequence of integers as the foll ...
- 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 ...
- PAT 甲级 1054 The Dominant Color (20 分)
1054 The Dominant Color (20 分) Behind the scenes in the computer's memory, color is always talked ab ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- Spotlights【思维+前缀和优化】
https://blog.csdn.net/mengxiang000000/article/details/53291883 原博客地址 http://codeforces.com/group/1 ...
- springboot中使用cache和redis
知识点:springboot中使用cache和redis (1)springboot中,整合了cache,我们只需要,在入口类上加 @EnableCaching 即可开启缓存 例如:在service层 ...
- Java&Selenium 模拟鼠标方法封装
Java&Selenium 模拟鼠标方法封装 package util; import org.openqa.selenium.By; import org.openqa.selenium.W ...
- MongoDB同步机制
复制 在此页 冗余和数据可用性 在MongoDB中复制 异步复制 自动故障转移 读取操作 交易次数 更改流 附加的功能 甲副本集 MongoDB中是一组mongod其保持相同的数据集的过程.副本集提供 ...
- flask 杂记
参考资料:http://python.jobbole.com/84003/ https://flask-cn.readthedocs.io/en/latest/tutorial/ 加载配置: app ...
- FWT 等总结 题解
目录 与卷积: 代码: 或卷积: 代码: 异或卷积: 代码: FST:子集卷积 代码: 例题: CF914G 代码: uoj310[UNR #2]黎明前的巧克力 代码: CF662C Binary T ...
- Win7下如何安装切换jdk7和jdk8
一.安装好JDK1.7和1.8. 二.配置环境变量: 1. 创建三个JAVA_HOME.JAVA7_HOME,存放JDK7的安装路径.JAVA8_HOME,存放JDK8的安装路径.JAVA_HOME, ...
- HashMap判断键是否为null
用containsKey(),而不用get(): HashMap中,null可以作为键,这样的键只有一个:可以有一个或多个键所对应的值为null.当get()方法返回null值时,即可以表示HashM ...
- go - GOPATH配置
查看配置信息 go env 然后找到对应的 GOPATH=>修改为你自己的目录 ..liunx 系统下,注意要给权限 go bulid 编译文件 go run 先编译后执行. -------- ...
- html预加载之link标签
我们之前提及过link rel 里面有preload和prefetch.modulepreload,都是用于预加载资源 <link rel="preload" href=&q ...