pat 1023 Have Fun with Numbers(20 分)
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
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <map>
#include <stack>
#include <vector>
#include <queue>
#include <set>
#define LL long long
using namespace std;
const int MAX = ; long long A[] = {}, B[] = {}, len;
char s[MAX], s2[MAX];
bool is_equal()
{
for (int i = ; i <= ; ++ i)
if (A[i] != B[i]) return false;
return true;
} void calcS2()
{
int b = , temp[];
for (int i = , j = len - ; i < len; ++ i, -- j)
{
if (j != -) b += * (s[j] - '');
temp[i] = b % ;
b /= ;
if (b > && i == len - ) ++ len;
}
for (int i = , j = len - ; i < len; ++ i, -- j)
s2[j] = char('' + temp[i]);
} int main()
{
// freopen("Date1.txt", "r", stdin);
scanf("%s", &s);
len = strlen(s);
for (int i = ; i < len; ++ i)
A[s[i] - ''] ++;
calcS2();
len = strlen(s2);
for (int i = ; i < len; ++ i)
B[s2[i] - ''] ++;
if (is_equal()) cout <<"Yes" <<endl <<s2 <<endl;
else cout <<"No" <<endl <<s2 <<endl;
return ;
}
pat 1023 Have Fun with Numbers(20 分)的更多相关文章
- 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 分)(permutation是全排列题目没读懂)
1023 Have Fun with Numbers (20 分) Notice that the number 123456789 is a 9-digit number consisting ...
- 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 (20 分)
题意: 输入一个不超过20位的正整数,问乘2以后是否和之前的数组排列相同(数字种类和出现的个数不变),输出Yes或No,并输出乘2后的数字. AAAAAccepted code: #define HA ...
- 【PAT甲级】1100 Mars Numbers (20 分)
题意: 输入一个正整数N(<100),接着输入N组数据每组包括一行字符串,将其翻译为另一个星球的数字. AAAAAccepted code: #define HAVE_STRUCT_TIMESP ...
- PAT 甲级 1069 The Black Hole of Numbers (20 分)(内含别人string处理的精简代码)
1069 The Black Hole of Numbers (20 分) For any 4-digit integer except the ones with all the digits ...
- 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 (Advanced Level) Practice 1008 Elevator (20 分) 凌宸1642
PAT (Advanced Level) Practice 1008 Elevator (20 分) 凌宸1642 题目描述: The highest building in our city has ...
- PAT甲级:1152 Google Recruitment (20分)
PAT甲级:1152 Google Recruitment (20分) 题干 In July 2004, Google posted on a giant billboard along Highwa ...
- 1069 The Black Hole of Numbers (20分)
1069 The Black Hole of Numbers (20分) 1. 题目 2. 思路 把输入的数字作为字符串,调用排序算法,求最大最小 3. 注意点 输入的数字的范围是(0, 104), ...
随机推荐
- React Diff算法一览
前言 diff算法一直是React系统最核心的部分,并且由于演化自传统diff,使得比较方式从O(n^3)降级到O(n),然后又改成了链表方式,可谓是变化万千. 传统Diff算法 传统diff算法需要 ...
- Jenkinsfile与Json的转换
前段时间调研了下青云的kubesphere,意外的发现了一个插件,pipeline-model-definition-plugin,用了将jenkins的pipeline.json互相转换的,以前可能 ...
- Ubuntu 19.10 发布 | 云原生生态周报 Vol. 24
作者 | 木苏.进超.冬岛.元毅.心水.衷源 业界要闻 1.云原生编程语言 Pulumi 1.0 pulumi ,一款中立的开源云开发平台,Pulumi 支持多语言.混合云环境.完全可扩展.初期支持 ...
- java与java web数组括号的不同
由于之前学JAVA SE数组时习惯了数组括号的写法,到了Web这里写了有点不太习惯了,赶快写篇博客加深一下印象哈 一. java和java web中的数组的不同 java: int[] arr = n ...
- 关于git提交
16年申请注册的git账号,除了需要找一些有用的demo时会逛一下,其实一直没拿起来真实用过. 好了,说一下今天下午呕心沥血弄出来的东西,其实就是简单的用git小黑窗口推文件夹上去,本人较笨,会按照我 ...
- Yii 数据库重连告别General error: 2006 MySQL server has gone away
General error: 2006 MySQL server has gone away 错误原因 制造错误 解决办法 最新办法 错误原因 Mysql has gone away MySQL 服务 ...
- Oracle数据库 常见的SQL题,复习
01.查询员工表所有数据,并说明使用*的缺点 select * from emp 02.查询职位(JOB)为'PRESIDENT'的员工的工资 select sal from emp where jo ...
- text文本样式二
text-transform样式用于将元素的字母全都变成大小 letter-spacing设置字符之间的间距 <html> <head> <style type=&quo ...
- BOOL,int,float,指针变量 与“零值”比较的if语句
分别给出BOOL,int,float,指针变量 与“零值”比较的 if 语句(假设变量名为var) 解答: BOOL型变量:if(!var) int型变量: if(var==0) float型变量: ...
- ArangoDB安装方法整理
目录 方法一:镜像安装 方法二:离线安装 方法三:在线安装 启动与停止服务 一.镜像安装(推荐方法) 安装docker 安装方法参见docker安装方法整理. 安装arangodb镜像: docker ...