提交记录 21604
提交时间 |
评测时间 |
2024-04-15 18:02:39 |
2024-04-15 18:02:44 |
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int N=1e5+9;
string add(string s1,string s2) {
string s;
int len1=s1.length();
int len2=s2.length();
if(len1>len2) {
for(int i=1;i<=len1-len2;++i) s2='0'+s2;
}
else {
for(int i=1;i<=len2-len1;++i) s1='0'+s1;
}
int a=s1.length();
int temp,cf=0;
for(int i=a-1;i>=0;--i) {
temp=s1[i]-'0'+s2[i]-'0'+cf;
cf=temp/10;
temp%=10;
s=char(temp+'0')+s;
}
if(cf) s=char(cf+'0')+s;
return s;
}
string sub(string s1,string s2) {
string s;
int len1=s1.length();
int len2=s2.length();
if(len1>len2) {
for(int i=1;i<=len1-len2;++i) s2='0'+s2;
}
else {
for(int i=1;i<=len2-len1;++i) s1='0'+s1;
}
if(s1<s2) {
string ss=sub(s2,s1);
s.erase(0,s.find_first_not_of('0'));
ss='-'+ss;
return ss;
}
int a=s1.length();
int temp,cf=0;
for(int i=a-1;i>=0;--i) {
temp=s1[i]-'0'-(s2[i]-'0')+cf;
if(temp<0) {
cf=-1;
temp+=10;
}
else cf=0;
s=char(temp+'0')+s;
}
s.erase(0,s.find_first_not_of('0'));
return s;
}
string mul(string str1,string str2)
{
string str;
int len1=str1.length();
int len2=str2.length();
string tempstr;
for(int i=len2-1;i>=0;i--)
{
tempstr="";
int temp=str2[i]-'0';
int t=0;
int cf=0;
if(temp!=0)
{
for(int j=1;j<=len2-1-i;j++)
tempstr+="0";
for(int j=len1-1;j>=0;j--)
{
t=(temp*(str1[j]-'0')+cf)%10;
cf=(temp*(str1[j]-'0')+cf)/10;
tempstr=char(t+'0')+tempstr;
}
if(cf!=0) tempstr=char(cf+'0')+tempstr;
}
str=add(str,tempstr);
}
str.erase(0,str.find_first_not_of('0'));
return str;
}
void solve() {
string s1,s2;cin>>s1>>s2;
string s=mul(s1,s2);
cout<<s;
}
int main() {
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int _;_=1;
while(_--) solve();
return 0;
}
Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
Testcase #1 | 3 s | 5 MB + 148 KB | Time Limit Exceeded | Score: 0 | 显示更多 |
Judge Duck Online | 评测鸭在线
Server Time: 2025-07-18 17:50:28 | Loaded in 0 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠