PAT 1023 Have Fun with Numbers
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
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define maxnum 100005 int a[] = {};
int count1[] = {}; //分别对倍乘前后的位计数
int count2[] = {}; int main(){
string s;
cin >> s;
int len = s.size();
for(int i=;i < s.size();i++){
a[i] = s[i]-'';
}
for(int i=;i < len;i++){
count1[a[i]]++;
}
for(int i=;i < len/;i++){ //翻转
swap(a[i],a[len-i-]);
} int jinwei = ; //倍乘
for(int i=;i <= len;i++){
int num = a[i]* + jinwei;
a[i] = num%;
jinwei = (num)/;
} // for(auto num:a) cout << num << " "; int pos = ;
for(int i=;i >= ;i--){
if(a[i]){pos = i;break;}
}
for(int i=;i <= pos;i++){
count2[a[i]]++;
} int flag = ;
for(int i=;i < ;i++){
if(count1[i] != count2[i])flag = ;
}
if(flag) cout << "Yes" << endl;
else cout << "No" << endl; for(int i=pos;i >= ;i--){
cout << a[i];
} return ;
}
_
PAT 1023 Have Fun with Numbers的更多相关文章
- PAT 1023 Have Fun with Numbers[大数乘法][一般]
1023 Have Fun with Numbers (20)(20 分) Notice that the number 123456789 is a 9-digit number consistin ...
- 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 (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 ...
- 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 甲级 1023 Have Fun with Numbers (20 分)(permutation是全排列题目没读懂)
1023 Have Fun with Numbers (20 分) Notice that the number 123456789 is a 9-digit number consisting ...
- 浙大 pat 1023题解
1023. Have Fun with Numbers (20) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue ...
- 1023 Have Fun with Numbers (20 分)
1023 Have Fun with Numbers (20 分) Notice that the number 123456789 is a 9-digit number consisting ...
- PAT 甲级 1023 Have Fun with Numbers
https://pintia.cn/problem-sets/994805342720868352/problems/994805478658260992 Notice that the number ...
- PAT Advanced 1023 Have Fun with Numbers (20) [⼤整数运算]
题目 Notice that the number 123456789 is a 9-digit number consisting exactly the numbers from 1 to 9, ...
随机推荐
- mysql表分区存储过程
本文为博主原创,未经允许不得转载: 由于数据库一张表数据量有几千万条,而且在不断增长,看见公司前辈写了一个创建表分区的存储过程,感觉 甚是牛逼,在此供自己保留学习. /*PROCEDURE creat ...
- CentOS7使用firewalld和selinux
转载自莫小安的博客:https://www.cnblogs.com/moxiaoan/p/5683743.html 如何查看和使用selinux https://blog.csdn.net/edide ...
- hihoCoder 1116 计算(线段树)
http://hihocoder.com/problemset/problem/1116 题意: 思路: 用线段树解决,每个节点需要设置4个变量,sum记录答案,all记录整个区间的乘积,pre记录该 ...
- P3146 [USACO16OPEN]248 & P3147 [USACO16OPEN]262144
注:两道题目题意是一样的,但是数据范围不同,一个为弱化版,另一个为强化版. P3146传送门(弱化版) 思路: 区间动规,设 f [ i ][ j ] 表示在区间 i ~ j 中获得的最大值,与普通区 ...
- P1547 Out of Hay
传送门 练习 只是一个最小生成树的水题,拿来练练模板 AC代码: #include<iostream> #include<cstdio> #include<alg ...
- Linux硬盘分区满,但没有找到占用文件
原因查找: 此服务器上有写日志的操作,在写的同时我把要写入的文件删除了..因为在写操作不能创建文件的时候会写硬盘的block,这样会使硬盘利用率越来越低,可以使用lsof -n |grep delet ...
- .net unicode汉字互相转换
[两种方法].net unicode汉字互相转换 ========================================= //汉字转Unicode编码(ASCII) private str ...
- Oracle简单语句查询
语法3-1:简单查询语句语法 SELECT [DISTINCT] * |列名称[AS][列别名],列名称[AS][列别名],...FROM 表名称[表别名]; 在整个简单查询之中,主要有两个子句完成: ...
- Eclipse启动Web项目 Tomcat中webapps中没有项目文件夹
原文出处:https://blog.csdn.net/JYH1314/article/details/51656233 1.eclipse不像MyEclipse默认将项目部署到tomcat安装目录下的 ...
- Android自定义权限
一.自定义权限 自定义权限,一般是考虑到应用共享组件时的安全问题.我们知道在四大组件 AndroidManifest 中注册的时候,添加 exported = "true" 这一属 ...