PAT 甲级 1023 Have Fun with Numbers
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的更多相关文章
- 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 ...
- 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 ...
- 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 ...
- 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, ...
- 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 ...
- PAT 1023 Have Fun with Numbers
1023 Have Fun with Numbers (20 分) Notice that the number 123456789 is a 9-digit number consisting ...
- PAT 1023 Have Fun with Numbers[大数乘法][一般]
1023 Have Fun with Numbers (20)(20 分) Notice that the number 123456789 is a 9-digit number consistin ...
- 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 ...
- PAT甲级题解(慢慢刷中)
博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6102219.html特别不喜欢那些随便转载别人的原创文章又不给 ...
随机推荐
- 数据结构与算法-图的最短路径Dijkstra
一 无向图单源最短路径,Dijkstra算法 计算源点a到图中其他节点的最短距离,是一种贪心算法.利用局部最优,求解全局最优解. 设立一个visited访问和dist距离数组,在初始化后每一次收集一 ...
- 配置redis一直启动
1. 进入 DOS窗口 2. 在进入redis的安装目录 3. 输入:redis-server --service-install redis.windows.conf --loglevel verb ...
- CentOS 7.2重启网络报错 Failed to start LSB: Bring up/down
CentOS 7.2重启网络报错 Failed to start LSB: Bring up/down 我的虚拟机原本有两块网卡,一块叫eno16777736,另一块叫eno5033674.本来是正常 ...
- 【leetcode 简单】 第五十二题 有效电话号码
给定一个文本文件 file.txt,请只打印这个文件中的第十行. 示例: 假设 file.txt 有如下内容: Line 1 Line 2 Line 3 Line 4 Line 5 Line 6 Li ...
- flex Datagrid checkbox
<?xml version="1.0" encoding="utf-8"?><!-- http://blog.flexexamples.com ...
- installshield 判断mdmcpq.inf和usbser.sys 是否 存在
1.产品上位机程序,需要驱动支持,在安装 exe程序的时候,连同NET框架4.0和 .inf驱动文件,一起安装, 安装驱动的时候,会发现, 如果系统 C:\Windows\Inf 缺少mdmcpq. ...
- 1111: [POI2007]四进制的天平Wag
1111: [POI2007]四进制的天平Wag 链接 题意: 用一些四进制数,相减得到给定的数,四进制数的数量应该尽量少,满足最少的条件下,求方案数. 分析: 这道题拖了好久啊. 参考Claris的 ...
- 源码阅读-GlobalTimer
最近看到一篇文章推了一个开源项目,GlobalTimer.主要是可以用一个定时器来统一管理多个定时任务,可以针对特定任务进行管理. 一.原理 1.一个公共的timer 2.封装任务到自定义个Event ...
- 数据结构思维导图 Part1
刚刚结束数据结构的学习,在复习阶段,所以做来思维导图总结一下. 思维导图,顾名思义是应该有对思维有引导作用的,就像思维的整理术,然而想要学好什么,光看思维导图总是不够的. 树与图作为两个复杂非线性结构 ...
- Struts 2(三):示例→基于Struts 2的用户注册模块
示例→基于Struts2的用户注册模块 1.用户注册模块需求描述 在用户注册页面中填写用户信息,包括用户名.用户密码.确认密码.姓名等信息,填写完成后提交注册表单给Struts 2的业务控制器Acti ...