1023. Have Fun with Numbers (20)-(大整数乘法)
来源:互联网 发布:品浪渔具淘宝店促销 编辑:程序博客网 时间:2024/05/15 23:45
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<cstdio>#include<cstring>#include<algorithm>using namespace std;int main(){ int a[25],b[25]; char str[25],str2[25]; scanf("%s",str); int len=strlen(str); for(int i=0;i<len;i++){ a[i]=str[len-1-i]-'0'; } int i,carry=0; for(i=0;i<len;i++){ b[i]=(a[i]*2+carry)%10; carry=(a[i]*2+carry)/10; } if(carry){ b[i++]=carry; } int b_len=i; for(int i=0;i<b_len;i++){ str2[i]=b[b_len-1-i]+'0'; } str2[b_len]='\0';//切记不能忘记字符串结束字符 sort(str,str+len); sort(str2,str2+b_len);// printf("%s %s\n",str,str2); if(strcmp(str,str2)==0){ printf("Yes\n"); }else{ printf("No\n"); } for(int i=b_len-1;i>=0;i--){ printf("%d",b[i]); } printf("\n"); return 0; }
- 1023. Have Fun with Numbers (20)-(大整数乘法)
- 1023. Have Fun with Numbers (20)-PAT甲级真题(大整数运算)
- PAT 1023. Have Fun with Numbers (20) 模拟大数乘法
- PAT 1023 Have Fun with Numbers(简单计数+大整数)
- 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)
- 基于Spark的公安大数据实时运维技术实践
- ubuntu桌面上的任务栏和启动器不见了
- 排序算法
- LeakCanary——直白的展现Android中的内存泄露
- Math类中ceil、floor和round的用法
- 1023. Have Fun with Numbers (20)-(大整数乘法)
- 关于"Cannot change version of project facet Dynamic web module to 3.0"问题的简单解决方案(备忘)
- MySQL笔记六之 条件判断函数
- 微软中间语言
- JAVASCRIPT&CSS之RUN SUN
- HDU-2141
- SqlServer函数大全
- 负载均衡指Hash取模算法
- IE下document.getElementsByName无法获取DIV标签