Source:

PAT A1023 Have Fun with Numbers (20 分)

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的更多相关文章

  1. Java 位运算2-LeetCode 201 Bitwise AND of Numbers Range

    在Java位运算总结-leetcode题目博文中总结了Java提供的按位运算操作符,今天又碰到LeetCode中一道按位操作的题目 Given a range [m, n] where 0 <= ...

  2. POJ 2739. Sum of Consecutive Prime Numbers

    Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20050 ...

  3. [LeetCode] Add Two Numbers II 两个数字相加之二

    You are given two linked lists representing two non-negative numbers. The most significant digit com ...

  4. [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 ...

  5. [LeetCode] Count Numbers with Unique Digits 计算各位不相同的数字个数

    Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n. Examp ...

  6. [LeetCode] Bitwise AND of Numbers Range 数字范围位相与

    Given a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND of all numbers ...

  7. [LeetCode] Valid Phone Numbers 验证电话号码

    Given a text file file.txt that contains list of phone numbers (one per line), write a one liner bas ...

  8. [LeetCode] Consecutive Numbers 连续的数字

    Write a SQL query to find all numbers that appear at least three times consecutively. +----+-----+ | ...

  9. [LeetCode] Compare Version Numbers 版本比较

    Compare two version numbers version1 and version1.If version1 > version2 return 1, if version1 &l ...

随机推荐

  1. ubuntu15.4、16.4、17.4设置nginx自启动

    ubuntu15.4.16.4.17.4设置nginx自启动记录个小问题,备忘录.花了大半天的时间研究这个,网上大多ubuntu.centos的配置nginx开机自启的都是之前的 Upstart/Sy ...

  2. 弹出框中的AJAX分页

    $(function() { $("body").on("click",".set-topic",function(){ /*获取所有题目接 ...

  3. python 根据字典的键值进行排序

    1.利用key排序 d = {'d1':2, 'd2':4, 'd4':1,'d3':3,} for k in sorted(d): print(k,d[k]) d1 2d2 4d3 3d4 1 2. ...

  4. Django有办法打开HTTP长轮询连接吗?

    保持连接打开,直到发生事件. 解决方案 看看Django / Comet(推送):所有邪恶中最少的?或者彗星在Python中的最新推荐? - COMET是“ajax long-polling”的另一个 ...

  5. 15-vim-缩排和重复执行

    缩排和重复执行 命令 功能 >> 向右增加缩进 << 向左减少缩进 . 重复上次命令 缩排命令在开发程序时,统一增加代码的缩进比较有用! 一次性在选中代码前增加4个空格,就叫做 ...

  6. Python第五节 元组

    Python第八节 元组补充 元组从形式上看,和列表唯一不同的在于,列表是中括号,元组是小括号 元组内的元素不可更改 一. 创建 创建直接在小括号内写元素,用逗号隔开就好 创建空元祖只写一个小括号 元 ...

  7. Fastjson <= 1.2.47 远程命令执行漏洞

    一.漏洞利用过程 查看java版本:java -version jdk版本大1.8 openjdk versin "1.8.0_222" 下载漏洞利用文件:git clone ht ...

  8. js两个数组去重后,绑定控件,并支持模糊搜索数组项以及数组互移

    设计大概是这个样子的,很简单,两个div,两个互移按钮,一个搜索框,要求搜索框输入时,触发待选框的搜索项 <input class="form-control" placeh ...

  9. Android jniLibs下目录详解(.so文件)

    http://www.jianshu.com/p/b758e36ae9b5 最近又研究了一下,参考了一下:三星/联发科等处理器规格表 更新时间:2017年5月手机CPU架构体系分类及各大厂商 PS:我 ...

  10. 在AndroidStudio2.3.2下JNI开发的详细步骤(转)

    转自:http://blog.csdn.net/luhaoying1111/article/details/72468867 安装NDK 在工具栏点击File->Settings->App ...