https://pintia.cn/problem-sets/994805342720868352/problems/994805478658260992

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 file 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

题解: long long 会爆掉 所以字符串模拟加法
代码:
#include <cstdio>
#include <string>
#include <stack>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std; char s[2222], num[2222], sum[2222], c, summ[2222]; int main() {
scanf("%s", s);
int dot = 0;
bool flag = true;
int len = strlen(s);
int k = 0, ans = 0;
for(int i = len - 1; i >= 0; i--) {
sum[ans++] = '0' + (s[i] - '0' + s[i] - '0' + k) % 10;
k = (s[i] - '0' + s[i] - '0' + k) / 10;
}
if(k) {
sum[ans++] = '1';
flag = 0;
}
for(int i = 0; i <= ans / 2 - 1; i++)
swap(sum[i], sum[ans - i - 1]);
strcpy(summ, sum);
sort(s, s + len);
sort(summ, summ + ans);
if(strcmp(s, summ) != 0) flag = 0;
if(flag) printf("Yes\n");
else printf("No\n");
printf("%s\n", sum);
return 0;
}

  

PAT 甲级 1023 Have Fun with Numbers的更多相关文章

  1. PAT 甲级 1023 Have Fun with Numbers(20)(思路分析)

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

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

  3. PAT甲级——A1023 Have Fun with Numbers

    Notice that the number 123456789 is a 9-digit number consisting exactly the numbers from 1 to 9, wit ...

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

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

  6. PAT 1023 Have Fun with Numbers

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

  7. PAT 1023 Have Fun with Numbers[大数乘法][一般]

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

  8. pat 1023 Have Fun with Numbers(20 分)

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

  9. PAT甲级题解(慢慢刷中)

    博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6102219.html特别不喜欢那些随便转载别人的原创文章又不给 ...

随机推荐

  1. WPF样式、模板、装饰器学习

    [代码]

  2. 20155311 《Java程序设计》实验四 (Android程序设计)实验报告

    20155311 <Java程序设计>实验四 (Android程序设计)实验报告 实验内容 基于Android Studio开发简单的Android应用并部署测试; 了解Android.组 ...

  3. 20155336 2016-2017-2《JAVA程序设计》第一周学习总结

    # 20155336  2016-2017-2<JAVA程序设计>第1周学习总结 ## 教材学习内容总结 开学的第一周,带着些许的欣喜和好奇,听完了老师的第一堂课.说心里话学习JAVA仿佛 ...

  4. C#基础之Equals和Dispose

    1.equal()和运算符==的区别 由于C#中有值类型和引用类型,那么相等也分为值相等和引用相等.先来看一个值类型简单的例子,顺便也写了string类型的比较. static void Main(s ...

  5. [arc065E]Manhattan Compass[曼哈顿距离和切比雪夫距离转换]

    Description 传送门 Solution 题目要求的是曼达顿距离,对于每个点(x,y),我们把它变为(x-y,x+y),就可以转换成求切比雪夫距离了. 证明如下:$max(\left | (x ...

  6. 优步UBER司机全国各地奖励政策汇总 (4月11日-4月17日)

    滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...

  7. .net core 无法获取本地变量或参数的值,因为它在此指令指针中不可用,可能是因为它已经被优化掉了

    使用vs 发布.net CORE 项目,调试遇到了“无法获取本地变量或参数的值,因为它在此指令指针中不可用,可能是因为它已经被优化掉了”这个问题,弄了半天才发现是发布的时候没有设置为debug,做个总 ...

  8. cogs1341 永无乡

    cogs1341 永无乡 打了一发替罪羊树. 鬼故事:替罪羊树去掉重构(变成裸的二叉排序树)依然跑得过= = 启发式合并.每次把小的里面所有东西往大的里面一丢,每个点最多被丢\(log_2n\)次(丢 ...

  9. StringUtils工具类用法

    /*1.字符串以prefix开始*/ StringUtils.startsWith("sssdf","");//结果是:true StringUtils.sta ...

  10. linux 同步 rsync的使用——远程服务器同步配置

    一.背景介绍 由于需要和其他系统进行对接.文件的逻辑地址通过接口传递,而文件的实体需要通过服务器间的同步进行传输.在同事的建议下选择了rsync. 二.RSYNC介绍 RSYNC 有多种方式进行同步, ...