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 ...
随机推荐
- SuperSocket证书节点新增配置属性 "storeLocation"
你可以指定你想要加载的证书的存储地点: <certificate storeName="My" storeLocation="LocalMachine" ...
- CODE FESTIVAL 2017 qual A D Four Coloring(补题)
这题看了好几天才看懂,一直误解题解中的d * d了 题解中说把大的格子划分成d * d的方格,我划分的时候把格子当作点来算的,一直觉得那明明是(d-1) * (d-1),昨天刚反映过来 思路:把格子旋 ...
- setTimeout与setInterval有何区别?
①setTimeout和setInterval的语法相同.它们都有两个参数,一个是将要执行的代码字符串,还有一个是以毫秒为单位的时间间隔,当过了那个时间段之后就将执行那段代码. ②不过这两个函数还是有 ...
- HDU 2066最短路径Dijkstra、
思路:枚举所有起点城市然后比较每个起点所去喜欢城市的最小距离 #include<cstdio> #include<cmath> #include<cstring> ...
- [转]关于SSH与SSM的组成及其区别
前言 当下SpringBoot盛行,咱再聊聊SpringBoot盛行之前的框架组合,当做复习巩固哈. 在聊之前,得先说说MVC,MVC全名是Model View Controller,是模型(mode ...
- java io流与序列化反序列化
java的io是实现输入和输出的基础,可以方便的实现数据的输入和输出操作. 序列化 (Serialization)是将对象的状态信息转换为可以存储或传输的形式的过程.在序列化期间,对象将其当前状态写入 ...
- mysql 修改列为not null报错Invalid use of NULL value
场景:mysql 给表新增parent_id列,并设置为not null,保存时报错Invalid use of NULL value. 报错原因:因为已存在的数据的parent_id列为null,与 ...
- yum安装gcc和gcc-c++
本次总结参考 博客:http://blog.csdn.net/robertkun/article/details/8466700 ,非常 感谢他的博客,帮我解决了问题. 今天安装gcc-c++时出现 ...
- linux alloc_pages 接口
为完整起见, 我们介绍另一个内存分配的接口, 尽管我们不会准备使用它直到 15 章. 现 在, 能够说 struct page 是一个描述一个内存页的内部内核结构. 如同我们将见到的, 在内核中有许多 ...
- Educational Codeforces Round 63部分题解
Educational Codeforces Round 63 A 题目大意就不写了. 挺简单的,若果字符本来就单调不降,那么就不需要修改 否则找到第一次下降的位置和前面的换就好了. #include ...