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部分.语言是 ...
随机推荐
- 国内外自然语言处理(NLP)研究组
国内外自然语言处理(NLP)研究组 *博客地址 http://blog.csdn.net/wangxinginnlp/article/details/44890553 *排名不分先后.收集不全,欢迎 ...
- css3 鼠标悬浮动画效果
CSS3案例 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <ti ...
- HDU-3068-最长回文-马拉车算法模板题
给出一个只由小写英文字符a,b,c...y,z组成的字符串S,求S中最长回文串的长度. 回文就是正反读都是一样的字符串,如aba, abba等 Input输入有多组case,不超过120组,每组输入为 ...
- codeforces 1100D-Dasha and Chess
传送门:QAQQAQ 题意:This is an interactive task. 999*999国际象棋棋盘中有一个王和666个车,玩家走王,电脑走车,玩家先走,玩家的目的是让对方的车将到自己的王 ...
- Collection单列集合中的常用实现类
Collection 集合层次的根接口 List 有序 有索引 可以重复 ArrayList 底层数据结构是数组 查询快 增删快 线程不安全 效率高 LinkedList 底层数据结构是链表 查询慢 ...
- Mysql优化系列之数据类型优化
本篇是优化系列的第一篇:数据类型 为了不产生赘述,尽量用简洁的语言来描述. 在选择数据类型之前,首先要知道几个原则: 更小的通常更好 尽量使用可以正确存储数据的最小数据类型.更小的数据类型意味着更快, ...
- HTML5伪类选择器表单验证
input : required 选择必填表单域 input : focus : invalid 选择当前聚焦的且含有非法输入值的表单域 input : focus : valid 选择当前聚焦的 ...
- python列表的常用操作
列表是python的基础数据类型之一 ,其他编程语言也有类似的数据类型.比如JS中的数 组, java中的数组等等. 它是以[ ]括起来, 每个元素用' , '隔开而且可以存放各种数据类型: 列表是p ...
- <爬虫>黑板爬虫闯关02
import requests from lxml import etree ''' 黑板爬虫闯关02 网址:http://www.heibanke.com/lesson/crawler_ex01/ ...
- angular 级联选择
HTML: <link rel="stylesheet" href="views/tree/checkbox.css"/> <div clas ...