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. 2018面向对象程序设计(Java)第4周学习指导及要求

    2018面向对象程序设计(Java) 第4周学习指导及要求(2017.9.19-2017.9. 26)   学习目标 掌握类与对象的基础概念,理解类与对象的关系: 掌握对象与对象变量的关系: 掌握预定 ...

  2. 附加任务:团队作业7 Alpha冲刺

    附加任务:团队作业7 Alpha冲刺 附加任务要求参考东北师范大学陈志勇老师博客:https://edu.cnblogs.com/campus/nenu/2016SE_NENU/homework/19 ...

  3. shell脚本中比较两个小数的办法

    具体情况#man bc 然而对小数进行比较的相关方法有几个: 1. 自己的解决方法,判断小数点后最多有几位数(N),然后对将要比较的两个数值进行 乘与10的N次方 也就是将小数点去掉来进行比较(小数点 ...

  4. maven打包报错:Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.5:test

    mvn package的时候报如下错误: Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.5:test ...

  5. GO注释

    1.GO资源简介 由于生物系统的惊人复杂性和需要分析的数据集的不断增加,生物医学研究越来越依赖于以可计算的形式存储的知识.基因本体论(GO)项目为基因功能和基因产物的可计算知识提供了目前最全面的资源. ...

  6. 04_web基础(五)之cookie与session

    29.Http协议无记忆带来的问题 什么是会话:可简单理解为:用户开一个浏览器,访问某一个web站点,在这个站点点击多个超链接,访问服务器多个web资源,然后关闭浏览器,整个过程称之为一次会话. 在一 ...

  7. prompt

    [prompt] prompt() 方法用于显示可提示用户进行输入的对话框. prompt(text,defaultText) 参数 描述 text 可选.要在对话框中显示的纯文本(而不是 HTML ...

  8. python学习day4 数据类型 if语句

    1.变量的内存管理 cpython解释器垃圾回收机制 什么是垃圾,当一个值身上没有绑定变量名时,(该值的引用计数=0时)就是一个垃圾 age=18 #18的引用计数=1 x=age  #18的引用计数 ...

  9. mac通过命令行获取证书和配置文件过期时间

      背景:ios打包证书的profile配置文件过期了,导致以前已经打完的测试包不能安装.所以需要加上检测机制,在打包时提示证书是否将要过期,如果要过期了给出提示   方案: 1.查找profile配 ...

  10. 【Scrapy】关于使用Scrapy框架爬虫遇到的问题1

    class testScrapy(scrapy.Spider): name = "testLogs" allowed_domains=["cnblogs.com" ...