C++ 20,本地能编译,提交过不了
查看原帖
C++ 20,本地能编译,提交过不了
442344
eofitg楼主2023/11/20 21:17

是C++20没错吧,本地我在CLion里面可以编译运行样例也能过,但是一提交连编译都编译不了,是split的问题吗,请教有没有懂这方面的人指点一下

# include <cstdio>
# include <iostream>
# include <sstream>
# include <cstring>

using namespace std;

vector<string> stringSplit(const string& str, char delim) {
    stringstream ss(str);
    string item;
    vector<string> elems;
    while (getline(ss, item, delim)) {
        if (!item.empty()) {
            elems.push_back(item);
        }
    }
    return elems;
}

int str2int(string str) {
    int n;
    istringstream iss;
    iss.clear();
    iss.str(str);
    iss>>n;
    return n;
}

int len(int n) {
    int ans = 0;
    if (n < 0) {
        ans ++;
        n = -n;
    }
    if (n > 0) {
        while (n) {
            n /= 10;
            ans ++;
        }
    } else {
        ans ++;
    }
    return ans;
}

int n;
string ch;
string symbol;

int main() {

    scanf("%d", &n);
    getchar();
    for (int i = 0; i < n; i ++) {
        getline(cin, ch);
        vector<string> str = stringSplit(ch,' ');
        int a = 0, b = 0;
        string sa, sb;
        if (str.size() == 3) {
            symbol = str[0];
            a = str2int(str[1]);
            b = str2int(str[2]);
            sa = str[1];
            sb = str[2];
        } else {
            a = str2int(str[0]);
            b = str2int(str[1]);
            sa = str[0];
            sb = str[1];
        }
        if (symbol == "a") {
            cout<<a<<'+'<<b<<'='<<a + b<<endl;
            cout<<sa.length() + sb.length() + 2 + len(a + b)<<endl;
        } else if (symbol == "b") {
            cout<<a<<'-'<<b<<'='<<a - b<<endl;
            cout<<sa.length() + sb.length() + 2 + len(a - b)<<endl;
        } else if (symbol == "c") {
            cout<<a<<'*'<<b<<'='<<a * b<<endl;
            cout<<sa.length() + sb.length() + 2 + len(a * b)<<endl;
        }
    }

    return 0;
}

2023/11/20 21:17
加载中...