博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
PAT 1023 Have Fun with Numbers[大数乘法][一般]
阅读量:4647 次
发布时间:2019-06-09

本文共 1841 字,大约阅读时间需要 6 分钟。

1023 Have Fun with Numbers (20)(20 分)

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:

Yes2469135798

题目大意: 对于输入一个不超过20位的数,判断*2之后的结果b的各位是否恰巧是原来的数组成的(不包含新的数)。

#include 
#include
#include
using namespace std;int hasN[10],hasM[10];int main(){ //用long long好吗?,使用long long在牛客网上通过率为56.25%。 //需要模拟大数乘法。 //直接用string好了,可以reverse. char ch[30]; scanf("%s",&ch); int len=strlen(ch); for(int i=0;ch[i]!='\0';i++){ hasN[ch[i]-'0']+=1;//计算所含每个数的个数。 } //将字符数组反转。 int cha; for(int i=0;i
=0;i--){ printf("%c",ch[i]); } return 0;}

 

//这是我的AC代码,在牛客网上提交了3次。

1.直接用long long通不过,因为有很大的数。

2.使用字符数组,发现最终结果是错误的,因为没有将其倒序输出。

3.提交一个也没通过,因为发现,模拟数乘,需要将初始的倒序。

总之就是:将初始倒序,相乘,结果倒序输出。

学习到了:

1.判断字符数组的长度,使用strlen,头文件是<string.h>,不包括'\0'。

2.使用scanf读入字符输出,结束处会自己带一个'\0'。 

转载于:https://www.cnblogs.com/BlueBlueSea/p/9438223.html

你可能感兴趣的文章
Git详解之四:服务器上的Git
查看>>
[NOIP2002]矩形覆盖
查看>>
JavaScript 复杂判断的更优雅写法借鉴
查看>>
hdu 5186 zhx's submissions
查看>>
<mvc:annotation-driven/>浅析
查看>>
ArcEngine开发之自定义工具
查看>>
SQL视频总结
查看>>
P4878 道路修建-美国
查看>>
dp练习
查看>>
vim
查看>>
苹果电脑包管理
查看>>
maze_travel的隐私声明
查看>>
对正则表达式又重新学了一遍,笔记方便以后查阅
查看>>
NSArray和NSString的联合使用
查看>>
UIKit应用 - Swift 版本: 3.让UITableViewCell的背景色渐变
查看>>
Java反射
查看>>
building tool
查看>>
JS中for循环输出三角形
查看>>
字节对齐2
查看>>
kafka幂等producer
查看>>