国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 學(xué)院 > 開(kāi)發(fā)設(shè)計(jì) > 正文

1023. Have Fun with Numbers (20)-(大整數(shù)乘法)

2019-11-09 20:55:28
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

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';//切記不能忘記字符串結(jié)束字符 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; }
發(fā)表評(píng)論 共有條評(píng)論
用戶(hù)名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 兴安县| 清丰县| 东山县| 谢通门县| 古蔺县| 玉树县| 江津市| 静宁县| 黑龙江省| 平山县| 宁津县| 凭祥市| 临清市| 全州县| 瓮安县| 青冈县| 芦山县| 巴东县| 高青县| 玉溪市| 临颍县| 外汇| 探索| 昌邑市| 丽江市| 郧西县| 唐海县| 平昌县| 井冈山市| 虞城县| 新疆| 清新县| 嘉定区| 千阳县| 渭源县| 古蔺县| 芜湖市| 临洮县| 太仆寺旗| 枣阳市| 浦城县|