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:

1234567899
 

Sample Output:

Yes
2469135798
 #include<stdio.h>
#include<string.h>
int hash1[]={};
int hash2[]={}; int jud(char a[],int len)
{
if(a[]>=''&&a[]<='')
{
return ; //false代表不合格的进位大整数;
}
if(a[]==''&&len!=)
{
return ;
}
if(a[]==''&&len==)
{
return ;
}
if(a[]>=''&&a[]<'')
{
return ;
}
}
int main()
{
char a[];
int inta[],i,len,temp;
gets(a);
len=strlen(a);
/*将字符串数组转化为对应整数,存入变换的整数数组中*/
for(i=;i<len;i++)
{
inta[i]=a[i]-'';
hash1[inta[i]]++;
}
/*/检测输出
for(i=0;i<len;i++)
{
printf("%d",inta[i]);
}
*/
//检测变化数组内容的数字出现次数;
/**/
// printf("\n");
// for(i=0;i<10;i++)
// {
// printf("%d ",hash1[i]);
// }
/**/
// printf("\n");
int count=;
for(i=len-;i>;i--)
{
temp=inta[i]*+count;
if(temp>=)
{
count=;
}
else{
count=;
}
inta[i]=temp%;
}
inta[]=inta[]*+count;
//将变换数组*2 //判断数组
if( jud(a,len)==)
{ //对*2后的数组中数字出现的次数进行统计;
for(i=;i<len;i++)
{
hash2[inta[i]]++;
}
// for(i=0;i<10;i++)
// {
// printf("%d ",hash2[i]);
// } //比较两hash表是否完全相等
for(i=;i<;i++)
{
if(hash1[i]!=hash2[i])
{
printf("No\n");
for(i=;i<len;i++)
{
printf("%d",inta[i]);
}
return ;
}
}
printf("Yes\n");
for(i=;i<len;i++)
{
printf("%d",inta[i]);
}
} else if(jud(a,len)==)
{
printf("No\n");
for(i=;i<len;i++)
{
printf("%d",inta[i]);
}
}
else
{
printf("No\n");
for(i=;i<len;i++)
{
printf("%d",inta[i]);
}
} return ;
}

Have Fun with Numbers的更多相关文章

  1. Java 位运算2-LeetCode 201 Bitwise AND of Numbers Range

    在Java位运算总结-leetcode题目博文中总结了Java提供的按位运算操作符,今天又碰到LeetCode中一道按位操作的题目 Given a range [m, n] where 0 <= ...

  2. POJ 2739. Sum of Consecutive Prime Numbers

    Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20050 ...

  3. [LeetCode] Add Two Numbers II 两个数字相加之二

    You are given two linked lists representing two non-negative numbers. The most significant digit com ...

  4. [LeetCode] Maximum XOR of Two Numbers in an Array 数组中异或值最大的两个数字

    Given a non-empty array of numbers, a0, a1, a2, … , an-1, where 0 ≤ ai < 231. Find the maximum re ...

  5. [LeetCode] Count Numbers with Unique Digits 计算各位不相同的数字个数

    Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n. Examp ...

  6. [LeetCode] Bitwise AND of Numbers Range 数字范围位相与

    Given a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND of all numbers ...

  7. [LeetCode] Valid Phone Numbers 验证电话号码

    Given a text file file.txt that contains list of phone numbers (one per line), write a one liner bas ...

  8. [LeetCode] Consecutive Numbers 连续的数字

    Write a SQL query to find all numbers that appear at least three times consecutively. +----+-----+ | ...

  9. [LeetCode] Compare Version Numbers 版本比较

    Compare two version numbers version1 and version1.If version1 > version2 return 1, if version1 &l ...

  10. [LeetCode] Sum Root to Leaf Numbers 求根到叶节点数字之和

    Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number ...

随机推荐

  1. HTML5--语法

    一.标记方法 1.内容类型(ContentType)还是.text/html 2.声明:<!DOCTYPE html SYSTEM “about:legacy-compat”> 3.字符编 ...

  2. 字符串编辑距离(Edit Distance)

    一.问题描述定义字符串编辑距离(Edit Distance),是俄罗斯科学家 Vladimir Levenshtein 在 1965 年提出的概念,又称 Levenshtein 距离,是指两个字符串之 ...

  3. uva 100 The 3n + 1 problem (RMQ)

    uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem= ...

  4. H3C MDI/MDIX

  5. JS 动态表格

    表格 在script里面使用innerHTML获取标签体的内容,然后进行添加. 删除则是不断的获取父节点,利用父节点删除子节点. 在做这个的时候,要主要获取表格table的对象有两种方式,一是getE ...

  6. Linux 使用 Speedtest 测试网速

    Speedtest的linux客户端是用python写的一个安装包 安装python包管理器pip yum -y install python-pip 如果提示No package python-pi ...

  7. 我来教你用AWS IoT.Part1--配置和接入

    AWS的IOT服务在中国区才开放.由于工作原因需要简单试用评估.写一下自己简单试用的流程,供其他人参考. 直接贴流程 1.先注册一个类型(这里“类型”相对于编程,可以理解为父类,里面可以添加一些可继承 ...

  8. java 两种进程创建方式比较

    A extends Thread: 简单 不能再继承其他类了(Java单继承) 同份资源不共享 A implements Runnable:(推荐) 多个线程共享一个目标资源,适合多线程处理同一份资源 ...

  9. 移动端遇到的bug (长期更新)

    移动端遇到的bug border-radius和transform在一起的bug 当父级设置了border-radius+overflow:hidden的时候,圆角是可以包住子级的,这是个很常见的场景 ...

  10. 如何用for..of.. 遍历一个普通的对象?

    如何用for..of.. 遍历一个普通的对象? 首先了解一下for..of..: 它是es6新增的一个遍历方法,但只限于迭代器(iterator), 所以普通的对象用for..of遍历 是会报错的.下 ...