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 ;
}
Have Fun with Numbers的更多相关文章
- Java 位运算2-LeetCode 201 Bitwise AND of Numbers Range
在Java位运算总结-leetcode题目博文中总结了Java提供的按位运算操作符,今天又碰到LeetCode中一道按位操作的题目 Given a range [m, n] where 0 <= ...
- POJ 2739. Sum of Consecutive Prime Numbers
Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20050 ...
- [LeetCode] Add Two Numbers II 两个数字相加之二
You are given two linked lists representing two non-negative numbers. The most significant digit com ...
- [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 ...
- [LeetCode] Count Numbers with Unique Digits 计算各位不相同的数字个数
Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n. Examp ...
- [LeetCode] Bitwise AND of Numbers Range 数字范围位相与
Given a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND of all numbers ...
- [LeetCode] Valid Phone Numbers 验证电话号码
Given a text file file.txt that contains list of phone numbers (one per line), write a one liner bas ...
- [LeetCode] Consecutive Numbers 连续的数字
Write a SQL query to find all numbers that appear at least three times consecutively. +----+-----+ | ...
- [LeetCode] Compare Version Numbers 版本比较
Compare two version numbers version1 and version1.If version1 > version2 return 1, if version1 &l ...
- [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 ...
随机推荐
- xml path 列转行实例
SQL Server2005提供了一个新查询语法——For XML PATH(''),这个语法有什么用呢?想象一下这样一个查询需求:有两个表,班级表A.学生表B,要查询一个班级里有哪些学生?针对这个需 ...
- hdu 3790 最短路径问题(迪杰斯特拉)
最短路径问题 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Subm ...
- settTimeout vs setInterval
setTimeout:过一段固定的时间后,将代码提交到代码队列中排队. setInterval:每隔一段固定的时间,执行一次代码. 他们两都接受两个参数,第一个参数是字符串或者函数,第二个参数是设定的 ...
- 洛谷P3178 [HAOI2015]树上操作 题解 树链剖分+线段树
题目链接:https://www.luogu.org/problem/P3178 这道题目是一道树链剖分的模板题. 但是在解决这道问题的同事刷新了我的两个认识: 第一个认识是:树链剖分不光可以处理链, ...
- 手风琴jq实现
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- MFC/Win32里面调用qtwebkit
可以用qtwinmigrate 文档在:http://doc.qt.digia.com/solutions/4/qtwinmigrate/index.html 下载在:https://qt.gitor ...
- Python--day41--事件和信号量之模拟连接数据库并在连接三次后抛出连接超时异常
#事件被创建的时候#False状态 #wait()阻塞#True状态 #wait() 非阻塞#clear 设置状态为False#set 设置状态为True #数据库 --- 文件夹#文件夹里有好多ex ...
- Can you find it?——[二分查找]
Description Give you three sequences of numbers A, B, C, then we give you a number X. Now you need t ...
- 学习better-scroll与vue结合使用
better-scroll,移动端滚动场景需求的插件 例: 做一个上下滚动,左右两边关联(滑动右侧左侧对应的类别显示高亮,点击左侧的类别名称右侧滑动到对应的位置) 如图: 分析:滑动右侧的时候左侧对应 ...
- 前端导出&配置问题
<button class="search" onclick="method5('dataTable');">导出</button> 在 ...