求助,全RE

P1957 口算练习题

BLX32M_10 @ 2022-02-20 09:57:10


#include <string>
#include <iostream>
using namespace std;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, aa, bb, cc, len;
    string a, b, c;
    char last, f;
    stringstream ss;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        a = b = c = " ";
        len = 0;
        cin >> a >> b;
        if (getchar() != '\n')
            cin >> c;
        if (c[0] == ' ')
        {
            ss.clear();
            ss << a;
            ss >> aa;
            ss.clear();
            ss << b;
            ss >> bb;
            f = last;
        }
        else
        {
            ss.clear();
            swap(a, b);
            ss << a;
            ss >> aa;
            ss.clear();
            swap(a, c);
            ss << b;
            ss >> bb;
            switch(c[0])
            {
                case 'a':
                    f = '+';
                case 'b':
                    f = '-';
                case 'c':
                    f = '*';
                case 'd':
                    f = '/';
            }
        }
        len += a.size() + b.size() + 2;
        cout << aa << f << bb << '=';
        if (f == '+')
            cc = aa + bb;
        if (f == '-')
            cc = aa - bb;
        if (f == '*')
            cc = aa * bb;
        else
            cc = aa / bb;
        ss.clear();
        ss << cc;
        ss >> c;
        len += c.size();
        cout << cc << endl << len << endl;
    }
    return 0;
}

by Mzx20081003 @ 2022-02-20 10:04:07

前排


|