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<string>
#include<algorithm>
using namespace std;
int main() {
string a, b, c;
int up=0;
cin >> a;
for (int i = a.length() - 1; i >= 0; i--) { //字符串模拟加法器
b = to_string((a[i]-'0') * 2 % 10 + up)+b;
up = (a[i]-'0') * 2 / 10;
}
if (up) //补上进位
b = to_string(up) + b;
c = b;
sort(a.begin(), a.end()); //排序,若数字组成相同,排序后字符串也相同
sort(b.begin(), b.end());
if (a == b)
cout << "Yes" << endl;
else
cout << "No" << endl;
cout << c;
return 0;
}

PAT 甲级 1023 Have Fun with Numbers(20)(思路分析)的更多相关文章

  1. 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 ...

  2. PAT 甲级 1023 Have Fun with Numbers

    https://pintia.cn/problem-sets/994805342720868352/problems/994805478658260992 Notice that the number ...

  3. 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, ...

  4. 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 ...

  5. 1023 Have Fun with Numbers (20 分)

    1023 Have Fun with Numbers (20 分)   Notice that the number 123456789 is a 9-digit number consisting ...

  6. PAT甲级:1136 A Delayed Palindrome (20分)

    PAT甲级:1136 A Delayed Palindrome (20分) 题干 Look-and-say sequence is a sequence of integers as the foll ...

  7. 【PAT甲级】1023 Have Fun with Numbers (20 分)

    题意: 输入一个不超过20位的正整数,问乘2以后是否和之前的数组排列相同(数字种类和出现的个数不变),输出Yes或No,并输出乘2后的数字. AAAAAccepted code: #define HA ...

  8. PAT甲题题解-1023. Have Fun with Numbers (20)-大数加法

    和1024一样都是大数据的题,因为位数最多要20位,long long最多19位给一个num,求sum=num+num问sum包含的数字,是否是num的一个排列,即数字都一样,只是顺序不同罢了. #i ...

  9. PAT (Advanced Level) 1023. Have Fun with Numbers (20)

    手动模拟一下高精度加法. #include<iostream> #include<cstring> #include<cmath> #include<algo ...

随机推荐

  1. C#自制Web 服务器开发:用C#开发自己的Web服务器

    当输入: GET / HTTP/1.1 Accept: text/html, application/xhtml+xml, */* Accept-Language: zh-CN User-Agent: ...

  2. EMbedding

    FNN模型:非端到端 输入 --> 特征onehot --->FM 模型--->输出每个特征权重及因子值  ----> 输入神经网络  ----> 输出每个预测值 此为一 ...

  3. ubuntu14安装TensorFlow

    1.安装ubuntu 网址:https://www.cnblogs.com/blog4matto/p/5581914.html 选择ubuntu14的原因:最初是想安装16的,后来发现总出问题,网上查 ...

  4. git---远程仓库版本回滚

    开发中,发现有错误版本提交带远程分支master,怎么处理? 1 简介 最近在使用git时遇到了远程分支需要版本回滚的情况,于是做了一下研究,写下这篇博客. 2 问题 如果提交了一个错误的版本,怎么回 ...

  5. The APK failed to install. Error:Could not parse error string.

    问题一: The APK failed to install. Error:Could not parse error string. 今天拖拽自己的apk到模拟器上运行,报上述错误. 搜索解决方案. ...

  6. select字符串

    [select字符串] select通常用于选择某中的某一列.如有表Download: 通常用select选择某一列,如: 当select一个字符串时,则会返回如下值: 结论:select中传递一个字 ...

  7. pytest 学习笔记一:参数化与组织分层

    组织分层: 1.普通方式,和unittest分层类似: setup_module()  # 通常放在类外 setup_class(cls) setup(self) teardown(self) tea ...

  8. redis主从复制踩到的那些坑

    一.报错:* MASTER <-> SLAVE sync started # Error condition on socket for SYNC: No route to host解决: ...

  9. openstack(Pike 版)集群部署(七)--- Cinder 部署

    一.介绍 参照官网部署:https://docs.openstack.org/cinder/pike/install/index-rdo.html 继续上一博客进行部署:http://www.cnbl ...

  10. use crunch compression

    Crunch is a lossy compression format on top of DXTR texture compression. Textures will be converted ...