Submission

Status:
----------

Score: 0

User: 111

Problemset: I.Quick Math

Language: cpp

Time: 0.005 second

Submitted On: 2024-11-16 14:57:11

#include<bits/stdc++.h>
using namespace std;

int main(){
string a;
string b;
getline(cin,a);
getline(cin,b);
vector<int> ans;
int tod;
for(int i=a.length()-1; i>=0; i--){
	int count = a.length()-1-i;
	tod=0;
	for(int j=b.length()-1; j>=0; j--){
		int INDEXcount = b.length()-1-j;
		int temp;
		temp = (b[j]-'0')*(a[i]-'0')+tod;
		tod=temp/10;
		temp %= 10;
		if(ans.size()>INDEXcount+count){
			ans[INDEXcount+count]+=temp;
			continue;
		}
		ans.push_back(temp);
	}
	if(tod){
		ans.push_back(tod);
	}
}
for(int i=0; i<ans.size(); i++){
	if(ans[i]>9){
		if(i==ans.size()-1){
			ans.push_back(ans[i]/10);
			ans[i]%=10;
			break;
		}
		ans[i+1] += ans[i]/10;
		ans[i]%=10;
	}
}
for(int i=ans.size()-1; i>=0; i--){
	cout << ans[i];
}
}