problem

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 file 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

tip

answer


#include<iostream>
#include<set>
#include<cstring>
#include<algorithm> #define LL long long
using namespace std; string a, da;
int na[22], nda[22]; void GetNum(string t, int *n){
if(t == "0") {
n[0]++;
return ;
}
for(int i = 0; i < t.size(); i++){
// s.insert(t[i]-'0');
n[t[i]-'0']++;
}
return ;
} string Double(string t){
string tt = "";
reverse(t.begin(), t.end());
int last = 0, th = 0;
for(int i = 0; i < t.size(); i++){
th = 2*(t[i]-'0') + last;
tt.push_back(th%10 + '0');
last = th/10;
}
if(last != 0) tt.push_back(last+'0');
// cout<<tt<<endl;
return tt;
} void PrintStatus(int *a){
for(int i = 0; i < 10; i++){
printf("%d ", a[i]);
}
printf("\n");
} int main(){
// freopen("test.txt", "r", stdin);
cin>>a;
da = Double(a);
memset(na, 0, sizeof(na));
memset(nda, 0, sizeof(nda)); GetNum(a, na);
GetNum(da, nda); // PrintStatus(na);
// PrintStatus(nda); bool flag = true;
for(int i = 0; i < 10; i++){
if(na[i] != nda[i]) flag = false;
} if(flag) puts("Yes");
else puts("No");
reverse(da.begin(), da.end());
cout<<da;
return 0;
}

exprience

  • 英语单词

    • permutation 排列
  • puts 与cout<<endl 差别
    • Cout是istream类的预定义对象,puts是预定义函数(库函数)。
    • cout是一个对象,它使用重载插入(<<)运算符函数来打印数据。 但是put是完整的函数,它不使用重载的概念。
    • cout可以打印数字和字符串。 而puts只能打印字符串。
    • cout在内部使用flush而puts并没有,为了刷新stdout,我们必须明确地使用fflush函数。
    • 要使用puts,我们需要包含stdio.h头文件。 在使用cout时我们需要包含iostream.h头文件。
    • puts函数会在结尾增加'\n'。

1023 Have Fun with Numbers (20)(20 point(s))的更多相关文章

  1. PAT 甲级 1001 A+B Format (20)(20 分)

    1001 A+B Format (20)(20 分) Calculate a + b and output the sum in standard format -- that is, the dig ...

  2. PAT 1054 求平均值 (20)(代码+思路+测试用例)

    1054 求平均值 (20)(20 分) 本题的基本要求非常简单:给定N个实数,计算它们的平均值.但复杂的是有些输入数据可能是非法的.一个"合法"的输入是[-1000,1000]区 ...

  3. A1027 Colors in Mars (20)(20 分)

    A1027 Colors in Mars (20)(20 分) People in Mars represent the colors in their computers in a similar ...

  4. A1046 Shortest Distance (20)(20 分)

    1046 Shortest Distance (20)(20 分)提问 The task is really simple: given N exits on a highway which form ...

  5. PAT 甲级 1011 World Cup Betting (20)(20 分)

    1011 World Cup Betting (20)(20 分)提问 With the 2010 FIFA World Cup running, football fans the world ov ...

  6. PAT 1049 数列的片段和(20)(代码+思路分析)

    1049 数列的片段和(20)(20 分) 给定一个正数数列,我们可以从中截取任意的连续的几个数,称为片段.例如,给定数列{0.1, 0.2, 0.3, 0.4},我们有(0.1) (0.1, 0.2 ...

  7. PAT 1033 旧键盘打字(20)(20 分)

    1033 旧键盘打字(20)(20 分) 旧键盘上坏了几个键,于是在敲一段文字的时候,对应的字符就不会出现.现在给出应该输入的一段文字.以及坏掉的那些键,打出的结果文字会是怎样? 输入格式: 输入在2 ...

  8. 【PAT】1019 数字黑洞 (20)(20 分)

    1019 数字黑洞 (20)(20 分) 给定任一个各位数字不完全相同的4位正整数,如果我们先把4个数字按非递增排序,再按非递减排序,然后用第1个数字减第2个数字,将得到一个新的数字.一直重复这样做, ...

  9. 【PAT】1018 锤子剪刀布 (20)(20 分)

    1018 锤子剪刀布 (20)(20 分) 大家应该都会玩“锤子剪刀布”的游戏:两人同时给出手势,胜负规则如图所示: 现给出两人的交锋记录,请统计双方的胜.平.负次数,并且给出双方分别出什么手势的胜算 ...

  10. PAT 甲级 1011 World Cup Betting (20)(20 分)(水题,不用特别在乎精度)

    1011 World Cup Betting (20)(20 分) With the 2010 FIFA World Cup running, football fans the world over ...

随机推荐

  1. jquery $.post() 向php传值 实现简单的二级联动

    更多内容推荐微信公众号,欢迎关注: 1 其中selectid是一个下拉菜单的id $().ready(function () { $("#selectid").change(fun ...

  2. 2016.5.16——leetcode:Rotate Array,Factorial Trailing Zeroe

    Rotate Array 本题目收获: 题目: Rotate an array of n elements to the right by k steps. For example, with n = ...

  3. mysql中使用日期加减时无法识别年-月格式数据的问题,%Y-%m"这种格式数据

    最新做报表统计的时候处理按月统计部分时发现,虽然使用 DATE_FORMAT( time, '%Y-%m' ) 函数可以将日期格式转成年-月,但是如果是参数是年-月格式,即"2018-10& ...

  4. 谈谈Linux内核驱动的coding style【转】

    转自:http://www.cnblogs.com/wwang/archive/2011/02/24/1960283.html 最近在向Linux内核提交一些驱动程序,在提交的过程中,发现自己的代码离 ...

  5. 【hdu6334】【2018Multi-University-Training Contest04】Problem C. Problems on a Tree

    维护1边的联通块和2边的联通块,合并的时候直接启发式合并. cdqz的大爷好强啊. #include<bits/stdc++.h> #define lson (o<<1) #d ...

  6. 【Educational Codeforces Round28】

    咸鱼选手发现自己很久不做cf了,晚节不保. A.Curriculum Vitae 枚举一下间断点的位置. #include<bits/stdc++.h> using namespace s ...

  7. Javascript中的Callback方法浅析

    什么是callback?  回调函数就是一个通过函数指针调用的函数.如果你把函数的指针(地址)作为参数传递给另一个函数,当这个指针被用为调用它所指向的函数时,我们就说这是回调函数.回调函数不是由该函数 ...

  8. mysql高可用架构 -> MHA简介-01

    作者简介 松信嘉範:MySQL/Linux专家2001年索尼公司入职2001年开始使用oracle2004年开始使用MySQL2006年9月-2010年8月MySQL从事顾问2010年-2012年 D ...

  9. python网络编程-paramiko

    python基础学习日志day8-paramiko 一:简介 Python的paramiko模块,该模块机遇SSH用于连接远程服务器并执行相关操作 现有这样的需求:需要使用windows客户端,远程连 ...

  10. show engine innodb status 详细介绍

    Contents Header1 SEMAPHORES. 1 LATEST DETECTED DEADLOCK. 3 TRANSACTIONS. 5 什么是purge操作... 5 FILE I/O. ...