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. Lastest Version Carprog Full V7.28 update and EEPROM reading

    Carprog Full has recently launched the newest V7.28 (with all software activated and all 21items Ada ...

  2. iOS类别(category)不能添加成员变量但是可以添加属性的问题

    类别不需要介绍了把,网上一大堆(利用Objective-C的动态运行时分配机制,可以为现有的类添加新方法,这种为现有的类添加新方法的方式称为类别catagory,他可以为任何类添加新的方法,包括那些没 ...

  3. 关于环信的WebIm的SDK一些使用注意

    先打自己几下脸,不好好看接口文档,啪啪啪. 主要先说下回调,直接先copy文档的 conn.listen({ onOpened: function ( message ) { //连接成功回调 //以 ...

  4. java调用.net asmx服务

    有时候,在java下开发会调用一下.net下写的服务,看网上有各种方法,但总是不成功,总结下自己测试过能调用成功的方式: 1. 原始方式http-soap public static String p ...

  5. jboss加密敏感信息

    默认情况下,我们配置在domain.xml或host.xml文件中的信息都是明文,对一些敏感信息就显得安全性不够,可以使用jboss提供的vault机制来进行加密 下面的内容来自 http://www ...

  6. LeetCode 142

    Linked List Cycle II Given a linked list, return the node where the cycle begins. If there is no cyc ...

  7. 关于VIM统计命令

    都是冒号命令哈::%s/./&/gn        统计字符数:%s/\i\+/&/gn    统计单词数:%s/^//n           统计行数:%s/keyword/& ...

  8. GD库使用小结---1

    因为一开始,“大家”都说一般任务中,用php操作图片不常见,像我们这种基本业务型的,就更用不到了,所以先别看,偶就没有看.现在有机会了自然要来玩一把. 以前学过C#的GDI+,交了课程设计后忘得一干二 ...

  9. 转 Android中this、super的区别

    在Java中,this通常指当前对象,super则指父类的.当你想要引用当前对象的某种东西,比如当前对象的某个方法,或当前对象的某个成员,你便可以利用this来实现这个目 的,当然,this的另一个用 ...

  10. 一个关于如何创建类似于QQ客户端聊天窗口的模拟小项目

    对于不久之前学习到的一个有关的类似于QQ聊天框的模拟项目,对其中涉及到的知识在这里做一下总结. 首先,你要先创建一个客户端聊天框(取名为:ChatClient,它是你创建的类),这个类继承了Frame ...