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. [OI]省选前模板整理

    省选前把板子整理一遍,如果发现有脑抽写错的情况,欢迎各位神犇打脸 :) 数学知识 数论: //组合数 //C(n,m) 在n个数中选m个的方案数 ll C[N][N]; void get_C(int ...

  2. <eq>标签

    链接:http://document.thinkphp.cn/manual_3_2.html#taglib <eq name="menu.id" value="1& ...

  3. 微服务深入浅出(1)-- SpringBoot

    基于Spring的开发框架,旨在简化配置快速开发,是新一代web开发框架.下面介绍一下常用的几个功能: 1.Spring单元测试 针对DAO层 (1) @RunWith(Spring.class),表 ...

  4. 【leetcode 简单】 第九十八题 第三大的数

    给定一个非空数组,返回此数组中第三大的数.如果不存在,则返回数组中最大的数.要求算法时间复杂度必须是O(n). 示例 1: 输入: [3, 2, 1] 输出: 1 解释: 第三大的数是 1. 示例 2 ...

  5. Python练习-从小就背不下来的99乘法表

    心血来潮,灵机一动,反正就是无聊的做了一个很简单的小玩意: for i in range(1,10):#让i 1-9 循环9次 print("\n")#每循环一次进行一次换行 fo ...

  6. iOS学习笔记(1)— UIView 渲染和内容管理

    iOS中应用程序基本上都是基于MVC模式开发的.UIView就是模型-视图-控制器中的视图,在iOS终端上看到的.摸到的都是UIView. UIView在屏幕上定义了一个矩形区域和管理区域内容的接口. ...

  7. 2016.6.21——Add Binary

    Add Binary 本题收获: 对于相加而言,考虑进位以及进位之后的值为多少,全部进位完毕后进位还为1(11 + 11 = 110)需要添加一位.1.string中默认每个元素为char型 2.从i ...

  8. mysql处理旧数据-使用模板以及临时表,不建议直接使用本表!!

    一 业务背景新版本中新建了一个项目的角色表,即每个项目都拥有几个角色,原来历史项目是没有角色的,这就要求使用脚本对表中的历史项目进行处理, 业务需求:每个项目都要有三个角色: 表 : pm_proje ...

  9. 【算法学习】manacher

    manacher太水了. 这篇blog不能称作算法学习,因为根本没有介绍…… 就贴个模板,太简单了…… #include<cstdio> #include<cstring> # ...

  10. idea git revert 究竟做了啥

    git里面实现撤销commit 这个据我目前所知,有至少4个途径可以做到 1.git reset 2.git revert 3.git rm –cached 4.git checkout 这个可以参考 ...