PAT甲级——A1023 Have Fun with Numbers
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 <algorithm>
#include <string>
using namespace std;
//会溢出,不能使用简单的加减
int main()
{
string a, b = "", res;
cin >> a;
int k = ;
for (int i = a.length() - ; i >= ; --i)
{
k = k + (a[i] - '') + (a[i] - '');
b += k % + '';
k /= ;
}
if (k > )
b += k + '';
res.assign(b.rbegin(), b.rend());
sort(a.begin(), a.end());
sort(b.begin(), b.end());
if (a == b)
cout << "Yes" << endl;
else
cout << "No" << endl;
for (auto c : res)
cout << c;
cout << endl;
return ;
}
PAT甲级——A1023 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
https://pintia.cn/problem-sets/994805342720868352/problems/994805478658260992 Notice that the number ...
- 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甲级题解(慢慢刷中)
博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6102219.html特别不喜欢那些随便转载别人的原创文章又不给 ...
- 【转载】【PAT】PAT甲级题型分类整理
最短路径 Emergency (25)-PAT甲级真题(Dijkstra算法) Public Bike Management (30)-PAT甲级真题(Dijkstra + DFS) Travel P ...
- 图论 - PAT甲级 1013 Battle Over Cities C++
PAT甲级 1013 Battle Over Cities C++ It is vitally important to have all the cities connected by highwa ...
- 图论 - PAT甲级 1003 Emergency C++
PAT甲级 1003 Emergency C++ As an emergency rescue team leader of a city, you are given a special map o ...
- PAT甲级题分类汇编——计算
本文为PAT甲级分类汇编系列文章. 计算类,指以数学运算为主或为背景的题. 题号 标题 分数 大意 1058 A+B in Hogwarts 20 特殊进制加法 1059 Prime Factors ...
- PAT甲级题分类汇编——序言
今天开个坑,分类整理PAT甲级题目(https://pintia.cn/problem-sets/994805342720868352/problems/type/7)中1051~1100部分.语言是 ...
随机推荐
- System.Web.Mvc.HttpPutAttribute.cs
ylbtech-System.Web.Mvc.HttpPutAttribute.cs 1.程序集 System.Web.Mvc, Version=5.2.3.0, Culture=neutral, P ...
- day 70 Django基础五之django模型层(二)多表操作
Django基础五之django模型层(二)多表操作 本节目录 一 创建模型 二 添加表记录 三 基于对象的跨表查询 四 基于双下划线的跨表查询 五 聚合查询.分组查询.F查询和Q查询 六 ORM ...
- “瑞士军刀”Netcat使用方法总结
前言 最近在做渗透测试的时候遇到了端口监听和shell的反弹问题,在这个过程中自己对Netcat这一款神器有了新的认识,现将一些Netcat的用法做一个小总结,希望对各位有帮助! Netcat简介 N ...
- day3:python测试题
1.Python的怎么单行注释和多行注释: 单行注释:# 多行注释: ''' ''' 或者 “”“ ”“” . 2.布尔值分别是什么 ? True /Fa ...
- oracle增加用户密码,cmd导入数据库
1.tomcat中sql语句 用户名 pdmis 密码pdmis create USER pdmis IDENTIFIED BY pdmis;grant create session to pdmis ...
- python函数基础(函数的定义和调用)
函数的定义 python定义函数使用def关键字 return[表达式]语句用于退出函数,选择性的向调用方返回一个表达式,不带参数值的return语句返回none def 函数名(参数列表): 函数体 ...
- 2019-5-15-影子系统让-C++-程序无法运行
title author date CreateTime categories 影子系统让 C++ 程序无法运行 lindexi 2019-05-15 15:24:35 +0800 2019-05-1 ...
- PyTorch中的C++扩展
今天要聊聊用 PyTorch 进行 C++ 扩展. 在正式开始前,我们需要了解 PyTorch 如何自定义module.这其中,最常见的就是在 python 中继承torch.nn.Module,用 ...
- win10下aria2和BaiduExporter的配置和安装
一.aria2的配置 下载 aria2下载地址: https://github.com/aria2/aria2/releases 链接:https://pan.baidu.com/s/1olJyZkX ...
- AM历史消息及文件记录删除
1.下载 folderclear.bat 文件 2.用编辑方式打开这个文件 3.对里面的参数做修改 4.这个批处理文件,保留了 完整的一个月的消息记录 (如 今天是 2017.3.15 ,那么 清除数 ...