样例都对但提交一个都过不起

P1957 口算练习题

WiseAnswer @ 2022-12-18 15:10:21

球球了

#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    getchar();
    int num1, num2;
    char opt;
    vector<string> vec_s;
    for (int i = 0; i < n; i++)
    {
        string line;
        getline(cin, line);
        istringstream iss(line);
        if (line[0] >= '0' && line[0] <= '9')
            iss >> num1 >> 
            num2;
        else
            iss >> opt >> num1 >> num2;
        ostringstream oss;
        switch (opt)
        {
        case 'a':
            oss << num1 << '+' << num2 << '=' << num1 + num2;
            break;
        case 'b':
            oss << num1 << '-' << num2 << '=' << num1 - num2;
            break;
        case 'c':
            oss << num1 << '*' << num2 << '=' << num1 * num2;
            break;
        }
        vec_s.push_back(oss.str());
    }
    for(int i=0;i<vec_s.size();i++){
        cout<<vec_s[i]<<endl<<vec_s[i].size()<<endl;
    }
}

by xainsir @ 2022-12-19 11:15:34

getline每行输入的字符串末尾可能还有多余的空格


|