七十分,搞不懂那里错了,求大佬点醒我

P1957 口算练习题

SunLakeWalk @ 2020-09-21 20:21:44

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

int t;
string s;
char pp[100];

void fun1(long long a, long long b){
    s += to_string(a);
    s += "+";
    s += to_string(b);
    s += "=";
    s += to_string(a + b);
}

void fun2(long long a, long long b){
    s += to_string(a);
    s += "-";
    s += to_string(b);
    s += "=";
    s += to_string(a - b);
}

void fun3(long long a, long long b){
    s += to_string(a);
    s += "*";
    s += to_string(b);
    s += "=";
    s += to_string(a * b);
}
int main(){
    cin >> t;
    while (t -- ){
        char p[100];
        cin >> p;

        s = "";
        if (p[0] == 'a'){
            long long a, b;
            cin >> a >> b;
            fun1(a, b);
        }
        else if (p[0] == 'b'){
            long long a, b;
            cin >> a >> b;
            fun2(a, b);
        }
        else if (p[0] == 'c'){
            long long a, b;
            cin >> a >> b;
            fun3(a, b);
        }
        else{
            long long b;
            cin >> b;

            long long sum = 0;
            int len = strlen(p);
            for (int i = 0; i < len; i ++ ){
                sum *= 10;
                sum += (p[i] - '0') ;
            }
            if (pp[0] == 'a') fun1(sum, b);
            else if (pp[0] == 'b') fun2(sum, b);
            else if (pp[0] == 'c') fun3(sum, b);
        }

        cout << s << endl;
        cout << s.size() << endl;

        pp[0] = p[0];
    }

    return 0;
}

|