Submission
Status:
PPPPPPP-PP
Subtask/Task Score:
90/100
Score: 90
User: Quinruj
Problemset: เลขหลักของผลคูณ
Language: cpp
Time: 0.002 second
Submitted On: 2025-10-05 20:49:51
#include <bits/stdc++.h>
using namespace std;
string pls(string a,string b){
reverse(a.begin(),a.end());
reverse(b.begin(),b.end());
while (a.size() < b.size()) a += '0';
while (b.size() < a.size()) b += '0';
reverse(a.begin(),a.end());
reverse(b.begin(),b.end());
string c = "";
int tod = 0;
for (int i = a.size()-1;i>=0;i--){
int sum = (a[i]-'0')+(b[i]-'0')+tod;
c += ((sum%10)+'0');
tod = sum/10;
}
if (tod != 0) c+=(tod+'0');
reverse(c.begin(),c.end());
return c;
}
string mul(string a,string b){
if (a.size() < b.size()) swap(a,b);
vector<string> w;
for (int i = b.size()-1;i>=0;i--){
string c = "";
int tod = 0;
for (int j = a.size()-1;j>=0;j--){
int multi = (b[i]-'0')*(a[j]-'0')+tod;
c += ((multi%10)+'0');
tod = multi/10;
}
if (tod != 0) c += (tod+'0');
reverse(c.begin(),c.end());
int cnt = b.size()-i-1;
for (int i = 0;i<cnt;i++) c+='0';
w.push_back(c);
}
string sum = "0";
for (int i = 0;i<w.size();i++){
sum = pls(w[i],sum);
}
return sum;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
string a,b;cin>>a>>b;
int x;cin>>x;
string s = mul(a,b);
if (x < s.size() && x > 0) cout << s[x-1];
else cout << '_';
}