求助
查看原帖
求助
349906
封禁用户楼主2020/6/21 20:14

本想来一个恶搞代码的,结果错了,希望大佬指教

#include <iostream>
#include <cstdio>
using namespace std;
typedef long long ll;
ll mi10(ll a)
{
    ll rtint = 1;
    for (ll i = 0; i < a; i++)
    {
        rtint *= 10;
    }
    return rtint;
}
ll toint(string s)
{
    ll ri = 0,fu=1;
    ll cnt = mi10(s.length() - 1);
    if (s[0] == '-')
    {
        fu = -1;
    }
    for (ll i = 0; i < s.length(); i++)
    {
        if (fu == 1)
        {
            ri += cnt * (s[i] - 48);
            cnt /= 10;
        }
        else
        {
            ri += cnt * (s[i+1] - 48);
            cnt /= 10;
        }
    }
    return ri*fu;
}
int main() {
    string a, b;
    cin >> a >> b;
    cout << toint(a) + toint(b);
    return 0;
}
2020/6/21 20:14
加载中...