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. [转]Web登录中的信心安全问题

    1. 一个简单的HTML例子看看用户信息安全 标准的HTML语法中,支持在form表单中使用<input></input>标签来创建一个HTTP提交的属性,现代的WEB登录中, ...

  2. makefile中重载与取消隐藏规则示例

    学习<跟我一起写Makefile-陈皓>后一直不懂,如何重载或取消隐藏规则 为了博客版面整洁,何为隐藏规则,Makefile基本规则编写等基础支持请自行百度. 需要声明的是:这些知识可能在 ...

  3. 课下实践——实现Mypwd

    实现Mypwd 学习pwd命令 想要知道当前所处的目录,可以用pwd命令,该命令显示整个路径名. L 目录连接链接时,输出连接路径 P 输出物理路径 研究pwd实现需要的系统调用(man -k; gr ...

  4. 【原创】Odoo开发文档学习之:ORM API接口(ORM API)(边Google翻译边学习)

    官方ORM API开发文档:https://www.odoo.com/documentation/10.0/reference/orm.html Recordsets(记录集) New in vers ...

  5. 苏州Uber优步司机奖励政策(4月18日)

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

  6. day 7 字符串

    6.字符串的常见操作 知道方向,不要去背 1)find,index #查找 2)count 和replace #替换 3)split # 分割(数据清洗) 4)capitalize 和 title # ...

  7. Oracle用户和模式,表空间

    oracle 用户与表空间关系 oracle用户与表空间关系用户=商家表=商品表空间=仓库1. 1个商家能有很多商品,1个商品只能属于一个商家2. 1个商品可以放到仓库A,也可以放到仓库B,但不能同时 ...

  8. abp core版本添加额外应用层

    1.新建类库WebProject.Application.App 2.添加WebProjectApplicationAppModule.cs 3.注册模块 using Abp.Application. ...

  9. HttpClient使用详解 (一)

    Http协议的重要性相信不用我多说了,HttpClient相比传统JDK自带的URLConnection,增加了易用性和灵活性(具体区别,日后我们再讨论),它不仅是客户端发送Http请求变得容易,而且 ...

  10. Phaser游戏框架与HTML Dom元素之间的通信交互

    本想按照PHASER的HTML Dom元素官方实例:http://labs.phaser.io/index.html?dir=game%20objects/dom%20element/&q=  ...