60分求调
查看原帖
60分求调
1331235
xumingyu2024楼主2024/7/27 13:30
#include <bits/stdc++.h>
using namespace std;
int main() {
    long long n;
    cin >> n;
    string a[54];
    vector<string> ant;
    for (long long i = 1; i <= n; i++)
    {
        string tmp = "";
        cin >> a[i];
        string b, c;
        if (a[i] == "a" || a[i] == "b" || a[i] == "c")
        {
            if (a[i] == "a")
            {

                cin >> b >> c;
                long long sum = stoi(b) + stoi(c);

                tmp = tmp + b + "+" + c + "=" + to_string(sum);
                ant.push_back(tmp);
                ant.push_back(to_string(tmp.size()));
            }
            else if (a[i] == "b")
            {

                cin >> b >> c;
                long long sum = stoi(b) - stoi(c);

                tmp = tmp + b + "-" + c + "=" + to_string(sum);
                ant.push_back(tmp);
                ant.push_back(to_string(tmp.size()));
            }
            else
            {

                cin >> b >> c;
                long long sum = stoi(b) * stoi(c);

                tmp = tmp + b + "*" + c + "=" + to_string(sum);
                ant.push_back(tmp);
                ant.push_back(to_string(tmp.size()));
            }
        }
        else {
            if (a[i - 1] == "a")
            {

                cin >> b;
                long long sum = stoi(b) + stoi(a[i]);
                tmp = tmp + b + "+" + a[i] + "=" + to_string(sum);
                ant.push_back(tmp);
                ant.push_back(to_string(tmp.size()));
            }
            else if (a[i - 1] == "b")
            {

                cin >> b;
                long long sum = stoi(b) - stoi(a[i]);
                tmp = tmp + b + "-" + a[i] + "=" + to_string(sum);
                ant.push_back(tmp);
                ant.push_back(to_string(tmp.size()));
            }
            else if (a[i - 1] == "c")
            {
                cin >> b;
                long long sum = stoi(b) * stoi(a[i]);
                tmp = tmp + b + "*" + a[i] + "=" + to_string(sum);
                ant.push_back(tmp);
                ant.push_back(to_string(tmp.size()));
            }
        }
    }
    for (int i = 0; i < ant.size(); i++)
    {
        if (i != ant.size() - 1)
        {
            cout << ant[i] << endl;
        }
        else {
            cout << ant[i];
        }
        
    }
    return 0;
}
2024/7/27 13:30
加载中...