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. 2019年湖南多校第一场||2018-2019 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2018)

    第一场多校就打的这么惨,只能说自己太菜了,还需继续努力啊- 题目链接: GYM链接:https://codeforces.com/gym/101933 CSU链接:http://acm.csu.edu ...

  2. 简明Python教程 ~ 随书笔记

    本文是阅读<简明Python教程>所做的随书笔记,主要是记录一些自己不熟悉的用法,或者所看到的比较有意思的内容,本书英文版A Byte of Python, 中文译版 简明Python教程 ...

  3. awk的常用内置函数的使用【转】

    手把手教你在linux下熟悉使用awk的指令结构 (15) 大家好,今天和大家说一下awk吧.反正正则 早晚也要和大家说,不如一点一点和大家先交代清楚了,省得以后和大家说的时候,大家有懵的感觉... ...

  4. js选择checkbox值,组织成key-value形式,传值到后台

    最近项目中遇到这样一个问题,接口定义需要传一个Map<String,String[]> params的参数,需要在jsp页面组织数据到后台操作,所以记下来以后难免还会用到. 以下是java ...

  5. 认识我们的太阳系(Solar System)

    一.初识太阳系 如果太阳是一颗篮球,那么我们的地球是什么?? 如果太阳系里最大的行星:木星是一颗足球,那么我们的地球是什么?? 如果我们的地球是一颗排球,那么其他行星是什么?? 由此,我们可以看到,我 ...

  6. [转载]Windows服务编写原理及探讨(3)

    (三)对服务的深入讨论之下 现在我们还剩下一个函数可以在细节上讨论,那就是服务的CtrlHandler函数. 当调用RegisterServiceCtrlHandler函数时,SCM得到并保存这个回调 ...

  7. mybatis比hibernate处理速度快的原因

    mybatis:是面向结果集的.当要展示的页面需要几个字段时,springmvc会提供这几个字段并将其拼接成结果集,在转化为相应的对象. hibernate:是面向对象的.要展示的页面需要某些字段时, ...

  8. 17 Go Slices: usage and internals GO语言切片: 使用和内部

    Go Slices: usage and internals  GO语言切片: 使用和内部 5 January 2011 Introduction Go's slice type provides a ...

  9. ZOJ 3781 Paint the Grid Reloaded(DFS连通块缩点+BFS求最短路)

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5268 题目大意:字符一样并且相邻的即为连通.每次可翻转一个连通块X( ...

  10. Luogu P1535 【游荡的奶牛】

    搜索不知道为什么没有人写bfs觉得挺像是标准个bfs的 状态因为要统计次数,不能简单地跳过一个被经过的点这样的话,状态量会爆炸采用记忆化设dp[i][j][k]表示在第k分钟到达点(i,j)的方案数以 ...