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. iOS修改状态栏颜色

    application.statusBarStyle = .LightContent // 在APPlication中设置全局状态栏颜色,为白色 application.statusBarHidden ...

  2. C# 13位时间戳转换成标准时间C#代码

    原地址:https://www.cnblogs.com/yixuehan/p/5559244.html /// <summary> /// 时间戳转换成标准时间 /// </summ ...

  3. MySQL 安装mysql数据库

    原地址: https://www.cnblogs.com/jamespan23/p/5953133.html https://www.cnblogs.com/gbwpyq/p/6104786.html ...

  4. Django中使用mysql数据库并使用原生sql语句操作

    Django自身默认使用sqlite3这个轻量级的数据库,但是当我们开发网站时,sqlite3就没有mysql好,sqlite3适合一些手机上开发使用的数据库. 准备的软件mysql数据库,版本5.7 ...

  5. python模拟线性回归的点

    构造符合线性回归的数据点 import numpy as np import tensorflow as tf import matplotlib.pyplot as plt # 随机生成1000个点 ...

  6. poj2115-Looooops-(扩展欧几里得定理)

    C Looooops Time Limit: 1000MS   Memory Limit: 65536K Total Submissions:33752   Accepted: 9832 Descri ...

  7. linux键盘驱动

    http://blog.csdn.net/beyondhaven/article/details/5753182 http://blog.chinaunix.net/uid-20564848-id-7 ...

  8. c 中的单引号和双引号的使用

    1. 在c中,'A' 表示的是一个 character constant ,表示的是字符集的数值:而 "A" 表示的是一个字符串常量,代表的是指向字符串的指针.

  9. linux安装php-redis扩展

    wget http://pecl.php.net/get/redis-2.2.5.tgz #解压 tar zxvf redis-2.2.5.tgz #进入安装目录 cd redis-2.2.5 /us ...

  10. 同时启动多个Tomcat 和 Linux部署多个tomcat

    a.减压2份tomcat文件 b.修改其中一个tomcat 的http访问端口(默认为8080端口,这里改为8091) c.修改其中一个tomcat 的Shutdown端口(默认为8005端口,这里改 ...