40pts HELP!!!!!!!!!!!!!!!!!

P1957 口算练习题

vector_STL_ @ 2024-11-01 22:47:58

#include <iostream>
#include <string>
using namespace std;

int shuwei(int a) {
    int r = 0;
    while (a != 0) {
        r++;
        a /= 10;
    }
    return r;
}
char a;

int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int b, c;
        if (i == 0) {
            cin >> a >> b >> c;
        } else {
            if (!(cin >> b >> c)) {
                cin >> a >> b >> c;
            }
        }
        if (a == 'a') {
            cout << b << "+" << c << "=" << b + c << endl;
            cout << shuwei(b) + shuwei(c) + shuwei(b + c) + 2 << endl;
        }
        else if (a == 'b') {
            cout << b << "-" << c << "=" << b - c << endl;
            if (b - c < 0) {
                cout << shuwei(b) + shuwei(c) + shuwei(b - c) + 3 << endl;
            } else {
                cout << shuwei(b) + shuwei(c) + shuwei(b - c) + 2 << endl;
            }
        }
        else if (a == 'c') {
            cout << b << "*" << c << "=" << b *c << endl;
            cout << shuwei(b) + shuwei(c) + shuwei(b * c) + 2 << endl;
        }

    }
}

|