51nod 1027 大数乘法
来源:互联网 发布:手机控制电脑 python 编辑:程序博客网 时间:2024/06/05 21:52
1027 大数乘法
基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题
收藏
关注
给出2个大整数A,B,计算A*B的结果。
Input
第1行:大数A第2行:大数B(A,B的长度 <= 1000,A,B >= 0)
Output
输出A * B
Input示例
123456234567
Output示例
28958703552
原来存的大数加减乘除模板用了以后会超时,用数组来个简化版本的,模拟乘法
#include<cstdio>#include<cstring>const int maxn = 1010;char a[maxn],b[maxn];int aa[maxn],bb[maxn],c[2020];int main(){ int i,j; while(scanf("%s %s",a,b)!=EOF) { if(a[0]=='0'||b[0]=='0') {printf("0\n");continue;} memset(c,0,sizeof(c)); int l1=strlen(a),l2=strlen(b); // printf("%s %s\n",a,b); for(i=0;i<l1;i++) aa[i]=a[l1-i-1]-'0'; for(i=0;i<l2;i++) bb[i]=b[l2-i-1]-'0'; for(i=0;i<l1;i++) { for(j=0;j<l2;j++) { //模拟乘法, c数组保存每一位的值,i+j的值相等时对应的是同一位 c[i+j]=aa[i]*bb[j]+c[i+j]; c[i+j+1]=c[i+j+1]+c[i+j]/10; c[i+j]=c[i+j]%10; } } i=l1+l2; while(!c[i]) i--; for(;i>=0;i--) printf("%d",c[i]); printf("\n"); } return 0;}
阅读全文
0 0
- 51nod -1027 . 大数乘法
- 51nod 1027 大数乘法
- 51nod 1027 大数乘法
- 51nod 1027 大数乘法
- 51nod 1027 大数乘法
- 【51nod】1027 大数乘法
- 51Nod 1027 大数乘法
- 51Nod-1027-大数乘法
- 51Nod 1027 大数乘法
- 51nod 1027 大数乘法
- 51Nod 1027 大数乘法
- 51Nod 大数乘法
- 51nod 大数乘法
- 51Nod-1027-大数乘法
- 1027 大数乘法 ——51Nod
- 51nod oj 1027 大数乘法【数组模拟】
- 51Nod-1028-大数乘法 V2
- 【51nod 1028 大数乘法 V2】
- Android的内存泄漏分析
- eclipse 远程debug project
- spring生命周期
- SystemCare PRO4. 2新版(优化胜过360、无后门、系统清理加速、无需注册)完美破解
- 堆排序算法
- 51nod 1027 大数乘法
- C语言(25)士兵杀敌1
- oracle sys/system账户登录
- IAR6.x升级到IAR7.x在引导文件出现的Warning
- IAR 调试出现“program exit reached"
- mysql audit 执行流程
- 关系代数 (关系模型)
- CDH搭建hadoop集群
- vim插件之ctags