1023 Have Fun with Numbers (20 分)
 

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:

  1. 1234567899

Sample Output:

  1. Yes
  2. 2469135798
  1. #include<iostream>
  2. #include<vector>
  3. #include<queue>
  4. #include<stack>
  5. #include<algorithm>
  6. #include<string>
  7. using namespace std;
  8. int Array[];
  9. int main()
  10. {
  11. string num;
  12. cin >> num;
  13. int len = num.size();
  14. int flag = ;
  15. int temp = ;
  16. for (int i = len - ; i >= ; i--)
  17. {
  18. Array[num[i] - '']++;
  19. temp = (num[i] - '') * + flag;
  20. flag = ;
  21. if (temp> )
  22. {
  23. temp %= ;
  24. flag = ;
  25. }
  26. Array[temp]--;
  27. num[i] = '' + temp;
  28. }
  29. int flag1 = ;
  30. for(int i=;i<;i++)
  31. if (Array[i]!=)
  32. {
  33. flag1= ;
  34. break;
  35. }
  36. if (flag1)
  37. {
  38. cout << "No" << endl;
  39. if (flag)
  40. cout << "" << num;
  41. else
  42. cout << num;
  43. }
  44. else
  45. {
  46. cout << "Yes" << endl;
  47. if (flag)
  48. cout << "" << num;
  49. else
  50. cout << num;
  51. }
  52.  
  53. }

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

  1. PAT 甲级 1023 Have Fun with Numbers (20 分)(permutation是全排列题目没读懂)

    1023 Have Fun with Numbers (20 分)   Notice that the number 123456789 is a 9-digit number consisting ...

  2. PAT (Advanced Level) Practice 1023 Have Fun with Numbers (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1023 Have Fun with Numbers (20 分) 凌宸1642 题目描述: Notice that the number ...

  3. 【PAT甲级】1023 Have Fun with Numbers (20 分)

    题意: 输入一个不超过20位的正整数,问乘2以后是否和之前的数组排列相同(数字种类和出现的个数不变),输出Yes或No,并输出乘2后的数字. AAAAAccepted code: #define HA ...

  4. PAT 甲级 1069 The Black Hole of Numbers (20 分)(内含别人string处理的精简代码)

    1069 The Black Hole of Numbers (20 分)   For any 4-digit integer except the ones with all the digits ...

  5. 1069 The Black Hole of Numbers (20分)

    1069 The Black Hole of Numbers (20分) 1. 题目 2. 思路 把输入的数字作为字符串,调用排序算法,求最大最小 3. 注意点 输入的数字的范围是(0, 104), ...

  6. 1023 Have Fun with Numbers (20)(20 point(s))

    problem Notice that the number 123456789 is a 9-digit number consisting exactly the numbers from 1 t ...

  7. PAT Advanced 1023 Have Fun with Numbers (20) [⼤整数运算]

    题目 Notice that the number 123456789 is a 9-digit number consisting exactly the numbers from 1 to 9, ...

  8. PAT甲题题解-1023. Have Fun with Numbers (20)-大数加法

    和1024一样都是大数据的题,因为位数最多要20位,long long最多19位给一个num,求sum=num+num问sum包含的数字,是否是num的一个排列,即数字都一样,只是顺序不同罢了. #i ...

  9. PAT (Advanced Level) Practice 1120 Friend Numbers (20 分) (set)

    Two integers are called "friend numbers" if they share the same sum of their digits, and t ...

随机推荐

  1. 鼠年开元用逐浪CMS v8.13版-NoSQL安装更轻便

    作为国内领先的Zoomla!逐浪CMS,一直以来深受人道的除了其功能强大.性能稳定外,易用性也是其突出的现. 自Zoomla!逐浪CMS 8.x开始,官方在其程序包中,集成了一键安装进程,从而大大提升 ...

  2. aosp 制作 rom 刷机 添加厂家二进制驱动 及 出厂镜像

    首先介绍下背景知识. aosp 仅是一套源码,不含厂家驱动. CM安卓的厂家驱动是自行提取的. 一般的安卓手机分区,有 boot , system, user , Baseband 基带, recov ...

  3. 阿里AI芯片:12nm工艺、709平方毫米大核心

    含光出自<列子·汤问>篇有“上古三剑”一章,寓意含而不露,光而不耀,象征含光 800 无形却强劲的算力. 含光 800 是一款 AI 芯片,偏重推理.据介绍,1 颗含光 800 的算力相当 ...

  4. 【JDK】JDK源码分析-Semaphore

    概述 Semaphore 是并发包中的一个工具类,可理解为信号量.通常可以作为限流器使用,即限制访问某个资源的线程个数,比如用于限制连接池的连接数. 打个通俗的比方,可以把 Semaphore 理解为 ...

  5. c js 字符串反转

    1.例如:输入 i am     a student    输出 student a am i #include <stdio.h> #include <string.h> v ...

  6. postgresql自增字段初始值的设定

    在实际开发中会有这样的需求,想要自己设置表中自增字段的初始值. 比如:有一个your_table表中有一个自增字段id,我们知道,插入数据后,默认是从1开始自增的. 但是假如现在有一个需求,是要求id ...

  7. C++ 【静态成员】static修饰的成员

    首先,我们先通过字面意思来理解... 成员:成员变量.成员函数. static  修饰成员变量,还有修饰成员函数. static  声明为静态的,称为静态成员.不管这个类创建了多少个对象,静态成员只有 ...

  8. .NET 5 Preview 1的深度解读和跟进

    这几天微软.NET 团队发布了.NET 5 Preview-1, 如约而至.很兴奋,因为.NET Core和.NET Framework终于实现了大一统,同时也很期待,期待.NET 5能给我们带来哪些 ...

  9. angular 项目中遇到rxjs error TS1005:';'

    因为rxjs的版本问题,只需要在package.json 中将依赖的 rxjs:'^6.00' 改为 rxjs'6.00', 然后执行 npm update 更新下rxjs的依赖版本即可解决

  10. docker安装mysql主从

    docker安装mysql主从 启动主库: 1.docker run --name master -p 3306:3306 -e MYSQL_ROOT_PASSWORD=root -d mysql:5 ...