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. 2015 ACM-ICPC 亚洲区上海站 A - An Easy Physics Problem (计算几何)

    题目链接:HDU 5572 Problem Description On an infinite smooth table, there's a big round fixed cylinder an ...

  2. vue/cli3引入cesium

    vue/cli3引入cesium 一开始用了webpack结合vue引入vue:结果是各种bug,搞了半天.最后问了基友,发现vue脚手架这个·简单高效的方法,只需要几行代码就轻松地搞定啦! 方案一. ...

  3. redis zset 介绍

    $key = 'key'; //新增 zadd($key,分数,标识) //删除某个标识 zrem($key,标识) //查询某个标识的排名(从0开始的 所有在输出的时候要加一) zrevrank($ ...

  4. sql合并字段

    <!-- 对发送方式合并查询 --> <!--查询所有满足条件的营销活动 --> <select id="CRM-MK-ACT-DEFINE-SELECT&qu ...

  5. 转 Jmeter参数化--Post请求的Post body 参数化

    2018年01月22日 15:40:58 java2013liu 阅读数:2361收起 个人分类: Jemter   一.使用body data设置参数: 1,首先,使用Fiddler录制post请求 ...

  6. strtotime 获取当月最后一天的日期

    strtotime('last day of this month', $timestamp);

  7. 马士兵对话京东T6阿里P7(薪水):月薪5万,他为何要离职?

    马士兵大佬你知道吗? 你竟然不知道?你怎么可能不知道!你不知道是不可能的! 记得自己的第一行Java代码,你的Hello World是跟着谁学的吗?我的就是马士兵老师! 马士兵是唯一一个在当时讲课是让 ...

  8. CTU OPEN 2017 Shooting Gallery /// 区间DP

    题目大意: 给定n 给定n个数 选定一个区间留下其他消去 要求区间两端的两个数一样 若成功留下一个区间 则在选定区间的基础上 继续进行上述操作 直到无法再选出这样的区间 求最多操作数 按区间长度由短到 ...

  9. linux下nano命令大全

    nano是一个字符终端的文本编辑器,有点像DOS下的editor程序.它比vi/vim要简单得多,比较适合Linux初学者使用.某些Linux发行版的默认编辑器就是nano. nano命令可以打开指定 ...

  10. redis-布隆过滤器使用

    占用空间测试地址 https://krisives.github.io/bloom-calculator/