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. redis zset 介绍

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

  3. C#变量2

    |   版权声明:本文为博主原创文章,未经博主允许不得转载. 数据类型: (1).值类型 类型名称 CTS类型 说明 范围 ^ - ^-(--) ^-^-(-~) ^-^- ^-^- -(-^-) - ...

  4. CF914D

    CF914D 用线段树乱搞一下就行qwq #include<iostream> #include<cstring> #include<cstdio> #includ ...

  5. python之数据序列转换并同时计算数据

    问题 你需要在数据序列上执行聚集函数(比如 sum() , min() , max() ), 但是首先你需要先转换或者过滤数据 解决方案 一个非常优雅的方式去结合数据计算与转换就是使用一个生成器表达式 ...

  6. css点击按钮,依次动态展开面板动画效果

    <a href="#one">按钮1</a> <a href="#two">按钮2</a> <a href ...

  7. 使用python+ffmpeg批量转换格式

    需求:  给定一个文件夹路径,遍历该文件夹内的所有文件以及子文件夹内的文件,当所有后缀名为wav格式的文件转换为ogg格式的文件. import os # 获取目录下的所有文件列表 import fn ...

  8. ARM 汇编与C之间 的调用

    一. 汇编调用 C 1. 初始化栈 2. 初始化BSS段 (BSS 段是C语言存放未初始化的全局变量,或者初始化为0 的全局变量) 3 .使用 r0 ,r1, r2, r3 给函数传参,如果多于  4 ...

  9. windows 添加永久路由

    打开cmd 命令为: route  add  目的网络    mask   子网掩码     下一跳   -p 添加完成后 可以使用如下命令进行查看: route print

  10. InnoDB global status

    常见参数 Innodb_buffer_pool_pages_free 发现 Innodb_buffer_pool_pages_free 为0 ,则说明buffer_pool 已经被用光,需要增大 in ...