求助大佬,为什么只会输出一次

P1957 口算练习题

Guoaguo @ 2023-12-18 11:35:39

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

int main()
{
    int n;
    cin >> n;
    string* num = new string[n * 2];
    string abc;
    int times = 0;
    string tmp;
    int jishu = 0;
    int size = 0;

    while (size < n)
    {
        cin >> tmp;
        if (tmp == "a" || tmp == "b" || tmp == "c")
        {
            abc += tmp;
            size++;
            jishu = 0;
        }
        else
        {
            if (jishu == 3)
            {
                abc += abc[size];
                size++;
            }
            else
            {
                num[times++] = tmp;
            }
        }
        jishu++;
    }

    for (int i = 0; i < n && i < abc.size(); i++)
    {
        if (abc[i] == 'a')
        {
            string an = num[2 * i] + "+" + num[2 * i + 1] + "=" + to_string((stoi(num[2 * i]) + stoi(num[2 * i + 1])));
            cout << an << endl << an.size() << endl;
        }
        else if (abc[i] == 'b')
        {
            string an = num[2 * i] + "-" + num[2 * i + 1] + "=" + to_string((stoi(num[2 * i]) - stoi(num[2 * i + 1])));
            cout << an << endl << an.size() << endl;
        }
        else if (abc[i] == 'c')
        {
            string an = num[2 * i] + "*" + num[2 * i + 1] + "=" + to_string((stoi(num[2 * i]) * stoi(num[2 * i + 1])));
            cout << an << endl << an.size() << endl;
        }
    }

    delete[] num;
    return 0;
}

|