1023. Have Fun with Numbers (20)
来源:互联网 发布:cydia出现数据库黄字 编辑:程序博客网 时间:2024/05/23 19:23
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 <stdio.h>#include <string.h>void DoubleNum(char s1[],int n,char s2[]);int Check(char s1[],char s2[]);int main(){ char s1[25],s2[25]; scanf("%s",s1); DoubleNum(s1,strlen(s1),s2); if(Check(s1,s2)) printf("Yes\n%s",s2); else printf("No\n%s",s2);}void DoubleNum(char s1[],int n,char s2[]){ int i,add=0; for(i=n-1;i>=0;i--){ s2[i]=((s1[i]-'0')*2+add)%10+'0'; add=((s1[i]-'0')*2+add)/10; } if(add){ for(i=n;i>0;i--) s2[i]=s2[i-1]; s2[0]=add+'0'; s2[n+1]='\0'; } else s2[n]='\0';}int Check(char s1[],char s2[]){ int c[10]={0},i; if(strlen(s1)!=strlen(s2))r eturn 0; for(i=0;i<strlen(s1);i++) c[s1[i]-'0']++; for(i=0;i<strlen(s2);i++) c[s2[i]-'0']--; for(i=0;i<10;i++) if(c[i]!=0)return 0; return 1;}
- 1023. Have Fun with Numbers (20)
- 【PAT】1023. Have Fun with Numbers (20)
- 1023. Have Fun with Numbers (20)
- 1023. Have Fun with Numbers (20)
- 1023. Have Fun with Numbers (20)
- PAT: 1023. Have Fun with Numbers (20)
- 1023. Have Fun with Numbers (20)
- PAT 1023. Have Fun with Numbers (20)
- 1023. Have Fun with Numbers (20)
- PAT 1023. Have Fun with Numbers (20)
- PAT 1023. Have Fun with Numbers (20)
- 1023. Have Fun with Numbers (20)
- 1023. Have Fun with Numbers (20)
- 1023. Have Fun with Numbers (20)
- 1023. Have Fun with Numbers (20)
- 1023. Have Fun with Numbers (20)
- 1023. Have Fun with Numbers (20)
- 1023. Have Fun with Numbers (20)
- 利用项目管理软件简单解决金融软件外包管理难题
- iOS语音识别(科大讯飞SDK)
- 什么是JSONP
- ZABBIX API
- Hibernate 参数含有中文时查询结果为空
- 1023. Have Fun with Numbers (20)
- 安卓代码访问互联网
- I00038 自守数(Automorphic number)
- Leetcode 389. Find the Difference 找不同 解题报告
- POJ 1458Common Subsequence
- jquery分页插件pagination 的运用
- 二,MyBatis BaseTypehandler使用
- pycharm 2016 专业版 注册码 激活 一起支持官方正版
- ORACLCE sql如何判断字段的值是不是空值