Pat(Advanced Level)Practice--1023(Have Fun with Numbers)
来源:互联网 发布:mac chrome f12 编辑:程序博客网 时间:2024/06/06 09:00
Pat1023代码
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:1234567899Sample Output:
Yes2469135798
#include<cstdio>#include<cstring>#include<algorithm>#define MAX 25using namespace std;int main(int argc,char *argv[]){int i,j,len;char str[MAX];char str2[MAX];char ans[MAX];int temp;scanf("%s",str);len=strlen(str);str2[MAX-1]='\0';j=MAX-1;temp=0;for(i=len-1;i>=0;i--){temp=temp+(str[i]-'0')*2;str2[--j]=temp%10+'0';temp=temp/10;}if(temp!=0)//乘以2之后可能位数加一位str2[--j]=temp+'0';strcpy(ans,str2+j);sort(str,str+len);sort(str2+j,str2+MAX-1);if(strcmp(&str2[j],str)==0)printf("Yes\n");elseprintf("No\n");printf("%s\n",ans);return 0;}
- Pat(Advanced Level)Practice--1023(Have Fun with Numbers)
- PAT (Advanced Level) Practise 1023 Have Fun with Numbers (20)
- PAT (Advanced Level) Practise 1023 Have Fun with Numbers (20)
- 1023. Have Fun with Numbers (20) @ PAT (Advanced Level) Practise
- 【PAT Advanced Level】1023. Have Fun with Numbers (20)
- 【c++】PAT (Advanced Level)1023. Have Fun with Numbers (20)
- 【PAT (Advanced Level)】1023. Have Fun with Numbers (20)
- PAT (Advanced Level) Practise 1023. Have Fun with Numbers (20)
- [PAT (Advanced Level) ]1023. Have Fun with Numbers 解题文档
- 浙大 PAT Advanced level 1023. Have Fun with Numbers (20)
- 【PAT】【Advanced Level】1023. Have Fun with Numbers (20)
- PAT (Advanced Level) 1023. Have Fun with Numbers (20) 字符串翻倍,哈希
- 1023. Have Fun with Numbers (20)【字符串操作】——PAT (Advanced Level) Practise
- PAT 甲级 1023 Have Fun with Numbers
- PAT-1023-Have Fun with Numbers
- pat a 1023 Have Fun with Numbers
- pat Have Fun with Numbers
- PAT Have Fun with Numbers
- 线程局部类控制数据库连接
- sap abap memory与sap memory
- thinkphp 配置URL路由
- phpmyadmin导入(import)文件限制的解决办法
- headroom.js插件使用方法
- Pat(Advanced Level)Practice--1023(Have Fun with Numbers)
- Eclipse中小图标代表的含义
- 从数据库中读取字符串时其中的空格变成加号
- Git使用基础篇
- INSTALL_PARSE_FAILED_MANIFEST_MALFORMED
- android 的NDK在Windwos环境搭建(二)
- 关于最近激烈竞争的打车软件的一些看法
- android camera(四):camera 驱动 GT2005
- 黑马程序员-----java常量池(转载)