求助

P1001 A+B Problem

Wildcxj @ 2020-06-21 20:14:39

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

#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;
}

by mc小丸子 @ 2020-09-19 09:02:57

太复杂了


by yrb666 @ 2021-08-30 14:57:34

这不就完了,那么费劲干啥。。。


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long a,b;
    cin>>a>>b;
    cout<<a+b;
    return 0;
}

上一页 |