打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
string乘法

#include <iostream>

#include<string>

#include<algorithm>

using namespace std;

string multiply(string a,string b){

string c;

int i=0,j=0;int carry=0,temp=0;

for(i=0;i<a.length();i++){

        carry=0;

for(j=0;j<b.length();j++){

cout<<(a[a.length()-1-i]-48)<<'x'<<(b[b.length()-1-j]-48)<<' ';

temp=(a[a.length()-1-i]-48)*(b[b.length()-1-j]-48)+carry;

if(temp>9){carry=temp/10;temp=temp%10;}

else{carry=0;}

if(i+j==c.length()){c.push_back(temp+48);}

else{c[i+j]+=temp;

if(c[i+j]>57){c[i+j]-=10;carry+=1;}

}

 cout<<c<<endl;

}

if(carry){

   if(i+j==c.length()){c.push_back(carry+48);}

   }

   cout<<c<<endl;

}

reverse(c.begin(),c.end());

return c;

}

int main()

{

 string a,b;cin>>a>>b;

   cout << multiply(b,a);

   return 0;

}

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
c++笔试基础 之 06 字符串反转的方法
用VC++类实现快速排序(并输出过程)
“模板”学习笔记(8)
最长公共子序列 与 最长公共连续子串
fft算法
71 f0301
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服