Submission

Status:

----------

Subtask/Task Score:

0/100

Score: 0

User: SnowAveNode

Problemset: ตัวอักษรตัวแรกในคำ

Language: cpp

Time: 0.003 second

Submitted On: 2025-09-19 17:07:15

#include<bits/stdc++.h>
using namespace std;
int main() {
    cin.tie(nullptr) -> sync_with_stdio(false);
    int x; string A, B; cin >> A >> B >> x;

    auto strip = [](string s)->string{
        bool neg = false; size_t i = 0;
        if (s[0]=='-'||s[0]=='+') { neg = (s[0]=='-'); i=1; }
        while (i < s.size() && s[i]=='0') ++i;
        string t = (i==s.size() ? "0" : s.substr(i));
        if (t=="0") neg=false;
        return neg ? "-"+t : t;
    };

    A = strip(A); B = strip(B);
    if (A=="0" || B=="0") { cout << 0 << '\n'; return 0; }

    bool neg = (A[0]=='-') ^ (B[0]=='-');
    if (A[0]=='-'||A[0]=='+') A.erase(A.begin());
    if (B[0]=='-'||B[0]=='+') B.erase(B.begin());

    int n=A.size(), m=B.size();
    vector<int> res(n+m,0);

    for (int i=n-1;i>=0;--i){
        int da=A[i]-'0';
        for (int j=m-1;j>=0;--j){
            int db=B[j]-'0';
            int idx=i+j+1;
            int sum = da*db + res[idx];
            res[idx] = sum%10;
            res[idx-1] += sum/10;
        }
    }

    string out; out.reserve(n+m+1);
    int k=0; while(k<(int)res.size() && res[k]==0) ++k; // skip leading zeros
    if (neg) out.push_back('-');
    for (; k<(int)res.size(); ++k) out.push_back(char('0'+res[k]));
    cout << out[x-1] << '\n';
}