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:

Yes
2469135798

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

#include <iostream>
#include<string.h>
#include<stdio.h>
using namespace std; int hasN[],hasM[];
int main(){
//用long long好吗?,使用long long在牛客网上通过率为56.25%。
//需要模拟大数乘法。
//直接用string好了,可以reverse.
char ch[];
scanf("%s",&ch);
int len=strlen(ch);
for(int i=;ch[i]!='\0';i++){
hasN[ch[i]-'']+=;//计算所含每个数的个数。
}
//将字符数组反转。
int cha;
for(int i=;i<len/;i++){//
cha=ch[i];
ch[i]=ch[len-i-];
ch[len-i-]=cha;
}
int jin=,tp=,i;
for(i=;ch[i]!='\0';i++){
tp=(ch[i]-'')*+jin;
if(tp<) {
ch[i]=tp+'';
jin=;
}
else {
ch[i]=(tp%+'');
jin=;
}
}
if(jin==){
ch[i]='';
ch[i+]='\0';
}
bool flag=true;
for(int i=;ch[i]!='\0';i++){
hasM[ch[i]-'']+=;
} for(int i=;i<;i++){
if(hasN[i]!=hasM[i]){
flag=false;break;
}
}
if(flag)
cout<<"Yes\n";
else
cout<<"No\n";
//printf("%s",ch);
//计算结果应该倒序输出
len=strlen(ch);
for(int i=len-;i>=;i--){
printf("%c",ch[i]);
}
return ;
}

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

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

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

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

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

学习到了:

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

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

PAT 1023 Have Fun with Numbers[大数乘法][一般]的更多相关文章

  1. PAT 1023 Have Fun with Numbers

    1023 Have Fun with Numbers (20 分)   Notice that the number 123456789 is a 9-digit number consisting ...

  2. pat 1023 Have Fun with Numbers(20 分)

    1023 Have Fun with Numbers(20 分) Notice that the number 123456789 is a 9-digit number consisting exa ...

  3. PAT 甲级 1023 Have Fun with Numbers (20 分)(permutation是全排列题目没读懂)

    1023 Have Fun with Numbers (20 分)   Notice that the number 123456789 is a 9-digit number consisting ...

  4. PAT (Advanced Level) Practice 1023 Have Fun with Numbers (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1023 Have Fun with Numbers (20 分) 凌宸1642 题目描述: Notice that the number ...

  5. PAT 甲级 1023 Have Fun with Numbers(20)(思路分析)

    1023 Have Fun with Numbers(20 分) Notice that the number 123456789 is a 9-digit number consisting exa ...

  6. hdu1313 Round and Round We Go (大数乘法)

    Problem Description A cyclic number is an integer n digits in length which, when multiplied by any i ...

  7. 51nod 1027大数乘法

    题目链接:51nod 1027大数乘法 直接模板了. #include<cstdio> #include<cstring> using namespace std; ; ; ; ...

  8. [POJ] #1001# Exponentiation : 大数乘法

    一. 题目 Exponentiation Time Limit: 500MS   Memory Limit: 10000K Total Submissions: 156373   Accepted: ...

  9. 用分治法实现大数乘法,加法,减法(java实现)

    大数乘法即多项式乘法问题,求A(x)与B(x)的乘积C(x),朴素解法的复杂度O(n^2),基本思想是把多项式A(x)与B(x)写成 A(x)=a*x^m+b B(x)=c*x^m+d 其中a,b,c ...

随机推荐

  1. 使用__FILE__和__LINE__定位错误

    #include <stdio.h> int main() { printf("this fake error is in %s on line %d\n", __FI ...

  2. WP8.1学习系列(第六章)——中心控件Hub面板部分交互UX

    本主题中呈现的模型类似于适用于 Windows Phone 的具有主页菜单(中心或透视控件)的中心应用中描述的模型.正如之前的案例所示,你要向用户呈现不同的功能区域.此处的区别在于你可以在顶层呈现所有 ...

  3. 解决:SqlDateTime 溢出。必须介于 1/1/1753 12:00:00 AM 和 12/31/9999 11:59:59 PM 之间提示问题

    提示信息如下 “/”应用程序中的服务器错误. SqlDateTime 溢出.必须介于 1/1/1753 12:00:00 AM 和 12/31/9999 11:59:59 PM 之间. 问题现象: 问 ...

  4. laravel + php cgi + nginx在windows平台下的配置

    1.d:\xampp\php\php-cgi.exe -b 127.0.0.1:9000 -c d:\xampp\php\php.ini 2.nginx conf配置如下: #user nobody; ...

  5. LeetCode 16 3Sum Closest (最接近target的3个数之和)

    题目链接 https://leetcode.com/problems/3sum-closest/?tab=Description     Problem : 找到给定数组中a+b+c 最接近targe ...

  6. Dockerfile创建镜像

    Dockerfile是一个文本格式的配置文件,用户可以使用Dockerfile来快速创建自定义的镜像. Dockerfile由一行行命令语句组成,并且支持易#开头的注释行. 一般而言Dockerfil ...

  7. Unity3D 面试ABC

    最先执行的方法是: 1.(激活时的初始化代码)Awake,2.Start.3.Update[FixUpdate.LateUpdate].4.(渲染模块)OnGUI.5.再向后,就是卸载模块(TearD ...

  8. like to do vs like doing

    I like to eat apple 表示我喜欢吃苹果这种食物. I like eating apple 表示我喜欢吃苹果这种食物 或者 表示我喜欢吃苹果这个过程. like to do,表达的是倾 ...

  9. php中调用这个功能可以在web页面中显示hello world这个经典单词

    php程序写的时间长了,自然对他所提供的功能了如指掌,他所提供的一大堆功能,真是觉得很好用,但有时候会发现php也缺少一些功能,自己总是会产生为php添加一些自定义的功能的想法.久而久之,终于今天憋不 ...

  10. 《机器学习实践》程序清单3-7 plotTree函数

    这个plotTree函数,比较聪明,比较简化,比较抽象,作者一定是逐步优化和简化到这个程度的.我是花了小两天时间,断断续续看明白的,还是在参考了另一篇文章以后.这里是链接http://www.cnbl ...