40求调

P1957 口算练习题

vector_STL_ @ 2024-10-04 09:45:42

#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;
        a = a;
        if (cin >> a >> b >> c) {
            a = a;
            if (a == 'a') {
                cout << b << "+" << c << "=" << b + c << endl;
                cout << shuwei(b) + shuwei(c) + shuwei(b + c) + 2 << endl;
            }
            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;
                }
            }
            if (a == 'c') {
                cout << b << "*" << c << "=" << b *c << endl;
                cout << shuwei(b) + shuwei(c) + shuwei(b * c) + 2 << endl;
            }
        } else if (cin >> b >> c) {
            int r = a;
            if (r == 'a') {
                cout << b << "+" << c << "=" << b + c << endl;
                cout << shuwei(b) + shuwei(c) + shuwei(b + c) + 2 << endl;
            }
            if (r == '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;
                }
            }
            if (r == 'c') {
                cout << b << "*" << c << "=" << b *c << endl;
                cout << shuwei(b) + shuwei(c) + shuwei(b * c) + 2 << endl;
            }
        }
    }
}

|