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 ...
随机推荐
- 深入理解Kubernetes资源限制:内存
写在前面 当我开始大范围使用Kubernetes的时候,我开始考虑一个我做实验时没有遇到的问题:当集群里的节点没有足够资源的时候,Pod会卡在Pending状态.你是没有办法给节点增加CPU或者内存的 ...
- zend studio 13.6.1汉化包安装方法
1.这里介绍的是离线汉化包的安装,在线汉化安装总是失败,还是离线的方便 2.汉化安装过程中系统可能会弹出报错,忽略就可以(反正我现在就是忽略了在用着) 下面图片中的链接就是在线安装的链接,不管是在线还 ...
- [转载]Java 应用性能调优实践
Java 应用性能调优实践 Java 应用性能优化是一个老生常谈的话题,笔者根据个人经验,将 Java 性能优化分为 4 个层级:应用层.数据库层.框架层.JVM 层.通过介绍 Java 性能诊断工具 ...
- TCP的半连接
T C P提供了连接的一端在结束它的发送后还能接收来自另一端数据的能力.这就是所谓下载的半关闭.正如我们早些时候提到的只有很少的应用程序使用它.为了使用这个特性,编程接口必须为应用程序提供一种方式来说 ...
- linux实操_shell读取控制台输入
基本语法: read [选项] [参数] 选项: -p 指定读取值时的提示符 -t 指定读取值时等待的时间(秒),如果没有在指定的时间内输入,就不再等待了 参数: 变量:指定读取值的变量名 实例1:读 ...
- vscode插件-JavaScript(ES6) Code Snippets 缩写代表含义
Import and export Trigger Content imp→ imports entire module import fs from 'fs'; imn→ imports entir ...
- Oracle自动化安装脚本-part01-亲试ok
#!/bin/bash node_num=$1 base_config=./network.conf 网络配置文件 software_config=./software.conf 软件包 ...
- MySQL数据库有几种索引?分别是什么?
5种索引 1.主键索引 2.唯一索引 3.普通索引 4.全文索引 5.联合索引
- React项目性能优化
1. 使用生产版本和Fragment 1. 生产版本 确保发布的代码是生产模式下(压缩)打包的代码. 一般运行npm run build命令. 直接从webpack看配置文件,需要设置mode = ' ...
- React中生命周期
1.过时的生命周期(v16.3之前) 1.当前组件初次渲染: 绿色表示执行顺序. constructor(): 如果不需要初始化,可以直接省略,会自动补全该函数. 可以在这个方法中初始化this.st ...