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. unity3d热更新插件uLua学习整理

    前言 IOS不能热更新,不是因为不能用反射,是因为System.Reflection.Assembly.Load 无法使用System.Reflection.Emit 无法使用System.CodeD ...

  2. redis分布式锁Redisson扩展

    如果大家项目中Redis是多机部署的可以来好好看看这篇实现,讲的非常好. 使用Redisson实现分布式锁,Spring AOP简化之   源码 Redisson概述 Redisson是一个在Redi ...

  3. struts2漏洞信息

    渗透篇01-struts2漏洞利用  https://blog.csdn.net/qq_38055050/article/details/79841604 Struts2著名RCE漏洞引发的十年之思  ...

  4. node Cannot enqueue Quit after invoking quit.

    因为第二次调用数据库时连接关闭了,应该把connection.connect();放在请求的函数里面:不然第二次请求出错

  5. cakephp2.7的学习笔记1 —— 安装与配置

    CakePHP2.7的安装 下载 https://github.com/cakephp/cakephp/releases 解压后扔进你的www目录就可以直接访问 按照提示,修改这两项配置,替换成你喜欢 ...

  6. 无法加载DLL"***.dll":找不到指定的模块

    加载dll的路径不对. 绝对路径不合适,可以换成相对路径. 比如: 把dll放入bin目录下的debug或者release下,然后就可以直接“test.dll”了.不用加路径了. 注意:路径必须与发布 ...

  7. YouTube Cobalt 浏览器支持

    Cobalt介绍: Cobalt浏览器是YouTube公司定制的一款专用浏览器,Cobalt的使命,是在电视机端,使用灵活多变web形式实现流畅的交互操作,从而替代Android,与普通浏览器不同,C ...

  8. TOJ 3850: String Function Encoding

    传送门:http://acm.tzc.edu.cn/acmhome/problemdetail.do?&method=showdetail&id=3850 时间限制(普通/Java): ...

  9. Intent Activity跳转 传递数据 Bundle

    1.普通跳转: Intent intent=new Intent(); intent.setClass(MainActivity.this,NewActivity.class); //新建一个Inte ...

  10. checkbox/radio 样式修改

    只改颜色 input[type=radio],input[type=checkbox] { display: inline-block; vertical-align: middle; width: ...