PAT 甲级 1023 Have Fun with Numbers

时间:2022-12-17 22:41:50

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 &lpar;20 分&rpar;(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 &lpar;20&rpar; &lbrack;⼤整数运算&rsqb;

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

  5. PAT &lpar;Advanced Level&rpar; Practice 1023 Have Fun with Numbers &lpar;20 分&rpar; 凌宸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&lbrack;大数乘法&rsqb;&lbrack;一般&rsqb;

    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. 常用ubuntu命令

    解压缩.7z sudo apt-get install p7zip-full 7z x PACKAGE.7z 查看图片 eog A.png 关闭打开触摸板(触点) sudo rmmod psmouse ...

  2. windows 7 安装 scrapy

    基于64位 win7 系统 先到 http://www.lfd.uci.edu/~gohlke/pythonlibs/ 下载四个 wheel 文件: 1. lxml-3.4.4-cp27-none-w ...

  3. 耦合 Coupling the object-oriented paradigm &amp&semi;&amp&semi; data coupling

    Computer Science An Overview _J. Glenn *shear _11th Edition 耦 两个人一起耕地 one of the benefits of the ...

  4. QT下的darknet-GPU项目属性

    #------------------------------------------------- # # Project created by QtCreator 2018-08-04T19:39 ...

  5. BZOJ5306 HAOI2018染色(容斥原理&plus;NTT)

    容易想到枚举恰好出现S次的颜色有几种.如果固定至少有i种恰好出现S次,那么方案数是C(M,i)·C(N,i*S)·(M-i)N-i*S·(i*S)!/(S!)i,设为f(i). 于是考虑容斥,可得恰好 ...

  6. Study 8 —— 行块元素及定位

    行&块元素display:inline;display:block;display:inline-block; 盒模型padding[内边距]padding: 上下内边距 左右内边距;padd ...

  7. &lbrack;django&rsqb;django corepython核心编程

    model meta排序 class BlogPost(models.Model): title = models.CharField(max_length=150) body = models.Te ...

  8. Apache禁止显示目录结构

    打开文件:httpd-vhosts.conf: 禁止显示Apache目录列表-Indexes FollowSymLinks如何修改目录的配置以禁止显示 Apache 目录列表.缺省情况下如果你在浏览器 ...

  9. WCF客户端第一请求server特别慢,解决办法

    最近开发WCF应用的客户端,第一连接WCF后,请求数据返回的速度特别慢,不知道原因如何.最后改了下系统生成的APP.Config文件就好了,原来没有useDefaultWebProxy的选项,没有的时 ...

  10. SGU---107 水题

    题目链接: http://codeforces.com/problemsets/acmsguru/problem/99999/107 题目大意: 求n位数有多少个的平方末尾是987654321 思路: ...