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, ...
随机推荐
- Twenty score
1.上图中有两个人对读书的看法有较大的不同. There are two people in the cartoon who treat books in completely different w ...
- Nginx配置示例
server {listen 6080;server_name local.boheadmin; location / {proxy_pass http://127.0.0.1:8087;} loca ...
- Lintcode449-Char to Integer-Naive
Description Convert a char to an integer. You can assume the char is in ASCII code (See Definition, ...
- 测试驱动android
测试驱动android开发 在安卓模拟器或者真机上跑测试用例速度很慢.构建.部署.启动app,通常需要花费一分钟或者更久.这不是TDD(测试驱动开发)模式.Robolectric提供一种更好的方式. ...
- List<Model>转String 、String 转List<string>
var ltCode = from item in psw.VehicleInsuranceItem select item.Code; string code = string.Join(" ...
- SpringMVC+fastjson项目配置
首先这个项目得是maven项目,不是maven项目的自己引包,我就不多说了. <!-- https://mvnrepository.com/artifact/org.springframewor ...
- form提交不刷新,不跳转页面
利用 iframe 标签 ,后台form处理可以返回void <form action="" method="post" target="nm_ ...
- Web Api:基于RESTful标准
参考链接:http://www.cnblogs.com/lori/p/3555737.html 简单的了解到RESTful架构后,跟着以上链接做了一个小练习. Step1: 新建WebApi项目,新建 ...
- poj 1744 tree 树分治
Tree Time Limit: 1000MS Memory Limit: 30000K Description Give a tree with n vertices,each ed ...
- es6 - 函数 扩展
1. 可添加默认参数 function fn(name,age=17){ console.log(name+","+age); } fn("Amy",18); ...