Have Fun with Numbers
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 ;
}
最新文章
- 移动端性能优化动态加载JS、CSS
- 网页中插入swf动画(embed)
- Linux_使用Linux之安装jdk 7
- linux中deb怎样安装
- [PWA] 12. Intro to IndexedDB
- Hive 1、什么是Hive,Hive有什么用
- Maven java项目管理工具
- Protel99SE制作拼板的方法
- Lake Counting(poj 2386)
- bat文件无法双击运行
- CentOS安装Python教程
- 12、Python-网络编程
- Entity Framework技巧系列之二 - Tip 6 - 8
- SVG渐变
- Webpack 2 视频教程 009 - 配置 ESLint 实现代码规范自动测试 (上)
- Python--urllib3库详解1
- hdu4864 Task贪心好题
- 四则运算4(Android版)
- Git使用六:版本对比
- BT原理分析