标签:sample ace closed iostream mask col main enter names
2
3
6
#include <iostream> #include <vector> #include <string> using namespace std; string multi(string num1,string num2){ string ans="";int len1=num1.size(),len2=num2.size(),add=0; vector<long long>tmp(len1+len2-1); for(int i=0;i<len1;++i){ int p1=num1[i]-‘0‘; for(int j=0;j<len2;++j){ int p2=num2[j]-‘0‘; tmp[i+j]+=p1*p2; } } for(int i=tmp.size()-1;i>=0;--i){ int now=tmp[i]+add; tmp[i]=now%10; add=now/10; } while(add!=0){ int now=add%10; add/=10; tmp.insert(tmp.begin(),now); } for(auto a:tmp)ans+=to_string(a); if(ans.size()>0&&ans[0]==‘0‘)return "0"; return ans; } int main(int argc, char *argv[]) { string num1,num2; while(cin>>num1>>num2) cout<<multi(num1,num2)<<endl; return 0; }
标签:sample ace closed iostream mask col main enter names
原文地址:https://www.cnblogs.com/Rhythm-/p/9348898.html