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

 #include <iostream>

 #include <string>

 #include <algorithm>

 using namespace std;

 int aa[];

 int v1[];

 int v2[];

 int main()

 {

       string  ss;

     while(cin>>ss)

       {

           int i;

             for(i=;i<;i++)

             {

                 aa[i]=;

             }

             for(i=;i<;i++)

             {

               v1[i]=;

               v1[i]=;

             }

             int count=;

             for(i=ss.length()-;i>=;i--)

             {

                aa[count++]=ss[i]-'';

                v1[ss[i]-'']=;

             }

             for(i=;i<count;i++)

             {

                 aa[i]=aa[i]*;

             }

           int tem,len;

         for(i=;i<count;i++)

             {

                 if(aa[i]>)

                   {

                      tem=aa[i]/;

                      aa[i+]=aa[i+]+tem;

                      aa[i]=aa[i]%; 

                   }

             }

             if(aa[count]==) len=count;

             else len=count+;

         reverse(aa,aa+len);

         for(i=;i<len;i++)

         {

            v2[aa[i]]=;

         }

       bool ifis=true;

         for(i=;i<;i++)

         {

            if(v1[i]!=v2[i]) ifis=false;

         }

         if(ifis) cout<<"Yes"<<endl;

         else  cout<<"No"<<endl;

         for(i=;i<len;i++)

         {

            cout<<aa[i];

         }

         cout<<endl;

       }

       return ;

 }

Have Fun with Numbers (大数)的更多相关文章

  1. PAT 1023 Have Fun with Numbers[大数乘法][一般]

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

  2. hdu 5585 Numbers【大数+同余定理】

    Numbers Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Sub ...

  3. ACM学习历程—HDU5585 Numbers(数论 || 大数)(BestCoder Round #64 (div.2) 1001)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5585 题目大意就是求大数是否能被2,3,5整除. 我直接上了Java大数,不过可以对末尾来判断2和5, ...

  4. ural 1012. K-based Numbers. Version 2(大数dp)

    和1009相同,只是n达到了180位,可以模拟大数加和大数乘,这里用的java中的大数. import java.math.BigInteger; import java.util.Scanner; ...

  5. zoj Fibonacci Numbers ( java , 简单 ,大数)

    题目 //f(1) = 1, f(2) = 1, f(n > 2) = f(n - 1) + f(n - 2) import java.io.*; import java.util.*; imp ...

  6. 2017CCPC秦皇岛 G题Numbers&&ZOJ3987【大数】

    题意: 给出一个数n,现在要将它分为m个数,这m个数相加起来必须等于n,并且要使得这m个数的或值最小. 思路: 从二进制的角度分析,如果这m个数中有一个数某一位为1,那么最后或起来这一位肯定是为1的, ...

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

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

  8. UVa 11582 Colossal Fibonacci Numbers! 【大数幂取模】

    题目链接:Uva 11582 [vjudge] watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fil ...

  9. ZOJ - 3987 - Numbers (大数 + 贪心)

    参考自:https://blog.csdn.net/u013534123/article/details/78484494 题意: 给出两个数字n,m,把n分成m份,使得以下最小 思路: 或运算只有0 ...

随机推荐

  1. C++: Why pass-by-value is generally more efficient than pass-by-reference for built-in (i.e., C-like) types

    A compiler vendor would typically implement a reference as a pointer. Pointers tend to be the same s ...

  2. RMI学习

    前段时间学习JMX,知道可以使用rmi连接器,就顺便看下rmi是什么东西,RMI 全称Remote Method Invocation-远程方法调用,实现远程对象之间的调用,下面原理图来自网络 服务器 ...

  3. java+mysql实现保存图片到数据库,以及读取数据库存储的图片

    一:建表 二:获取数据库连接 1:导入mysql的驱动jar包,mysql-connector-java-5.1.8-bin.jar 2:写代码连接数据库,如下: /** * */ package c ...

  4. 转:C++ 性能测试支持

    转: http://codinginet.com/articles/view/201606-use_gtestx_for_benchmark?simple=1&from=timeline&am ...

  5. C# Windows Service服务的创建和调试

    前言 关于Windows服务创建和调试的文章在网络上的很多文章里面都有,直接拿过来贴在这里也不过仅仅是个记录,不会让人加深印象.所以本着能够更深刻了解服务项目的创建和调试过程及方法的目的,有了这篇记录 ...

  6. ActiveMQ 的安装

    1. 在 http://activemq.apache.org/ 下载 ActiveMQ.Windows 系统选择下载 apache-activemq-x.x.x-bin.zip,Unix/Linux ...

  7. 在Ubuntu系统中解压rar和zip文件的方法

    大家在以前的windows系统中会存有很多rar和zip格式的压缩文件,Ubuntu系统默认情况下对这些文件的支持不是很好,如果直接用"归档管理器"打开会提示错误,因此今天跟大家分 ...

  8. js和jQuery创建元素和把元素插入到文档中所用的方法

    js创建元素: document.createElement(" 创建的元素");   //“创建的元素”指:p ,h1,div,span........ js插入元素: docu ...

  9. Win7 IIS (HTTP Error 500.21 - Internal Server Error)解决

    今天在测试网站的时候,在浏览器中输入http://localhost/时,发生如下错误: HTTP Error 500.21 - Internal Server Error Handler " ...

  10. ios Swift 特性

    特性提供了关于声明和类型的更多信息.在Swift中有两类特性,用于修饰声明的以及用于修饰类型的.例如,required特性,当应用于一个类的指定或便利初始化器声明时,表明它的每个子类都必须实现那个初始 ...