PAT_A1023#Have Fun with Numbers
Source:
Description:
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
Keys:
Code:
/*
Data: 2019-07-11 20:38:07
Problem: PAT_A1023#Have Fun with Numbers
AC: 16:20 题目大意:
给定K位数,翻倍后,是否为原数的重排列
*/
#include<cstdio>
#include<string>
#include<algorithm>
#include<iostream>
using namespace std; string Double(string s)
{
string ans;
int carry=,len=s.size();
for(int i=; i<len; i++)
{
int temp = (s[len-i-]-'')*+carry;
ans.insert(ans.end(), temp%+'');
carry = temp/;
}
while(carry != )
{
ans.insert(ans.end(), carry%+'');
carry /= ;
}
reverse(ans.begin(),ans.end());
return ans;
} int main()
{
string s;
cin >> s;
string t = Double(s);
string p = t;
sort(s.begin(),s.end());
sort(t.begin(),t.end());
if(s == t) printf("Yes\n");
else printf("No\n");
cout << p; return ;
}
PAT_A1023#Have Fun with Numbers的更多相关文章
- Java 位运算2-LeetCode 201 Bitwise AND of Numbers Range
在Java位运算总结-leetcode题目博文中总结了Java提供的按位运算操作符,今天又碰到LeetCode中一道按位操作的题目 Given a range [m, n] where 0 <= ...
- POJ 2739. Sum of Consecutive Prime Numbers
Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20050 ...
- [LeetCode] Add Two Numbers II 两个数字相加之二
You are given two linked lists representing two non-negative numbers. The most significant digit com ...
- [LeetCode] Maximum XOR of Two Numbers in an Array 数组中异或值最大的两个数字
Given a non-empty array of numbers, a0, a1, a2, … , an-1, where 0 ≤ ai < 231. Find the maximum re ...
- [LeetCode] Count Numbers with Unique Digits 计算各位不相同的数字个数
Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n. Examp ...
- [LeetCode] Bitwise AND of Numbers Range 数字范围位相与
Given a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND of all numbers ...
- [LeetCode] Valid Phone Numbers 验证电话号码
Given a text file file.txt that contains list of phone numbers (one per line), write a one liner bas ...
- [LeetCode] Consecutive Numbers 连续的数字
Write a SQL query to find all numbers that appear at least three times consecutively. +----+-----+ | ...
- [LeetCode] Compare Version Numbers 版本比较
Compare two version numbers version1 and version1.If version1 > version2 return 1, if version1 &l ...
随机推荐
- HDU6655 Just Repeat(2019杭电多校J题)
原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=6655 简单博弈问题,A,B手里各有n,m张牌,牌有颜色,两人轮流出牌(A先出),一个人只能打出对放未打 ...
- Vue环境搭建及第一个helloWorld
Vue环境搭建及第一个helloWorld 一.环境搭建 1.node.js环境安装配置 https://www.cnblogs.com/liuqiyun/p/8133904.html 或者 htt ...
- 力扣算法——138CopyListWithRandomPointer【M】
A linked list is given such that each node contains an additional random pointer which could point t ...
- vmware安装minimal centos报错/etc/rc5.d/s99local : line:25 : eject : command not found
今天在用centos mini 版的时候创建虚拟机出现错误提示:vmware安装minimal centos报错/etc/rc5.d/s99local : line:25 : eject : comm ...
- 進階gdb之core dump的除錯
core dump的除錯 Basic Perl等語言處理的可以說是User的資料, C可以說在那邊把資料在記憶體移來移去, 組語可說把資料在暫存器搬來搬去, 越低階的處理表示握有的資源越少 所以C處理 ...
- 完全卸载win10上的Ubuntu子系统 - Windows Subsystem for Linux(WSL)
Ctrl + R 键入: lxrun /uninstall /full 具体请看 microsoft的说明:Frequently Asked Questions
- js中三元运算符的两种情况
一.一般情况 <script type="text/javascript"> var b=5; (b == 5) ? a="true" : a=&q ...
- Python之字符串正则匹配
需求: 正则表达式匹配某个文本模式,但是它找到的是模式的最长可能匹配(因为是贪婪匹配 ). 而你想修改它变成查找最短的可能匹配. import re text2 = 'Computer says &q ...
- display: flex属性介绍
参考文章: 阮大神的:Flexbox 布局的最简单表单(主要讲解项目item上的属性) 另一位大神的:布局神器display:flex(整体讲解的非常详细) 之前没有仔细看flex布局(弹性布局),设 ...
- swagger2.0与spring结合
官方文档: http://www.baeldung.com/swagger-2-documentation-for-spring-rest-api swagger是一个前后端api统一文档和测试框 ...