#29 WA 求助
查看原帖
#29 WA 求助
912750
CarrotMeow楼主2023/4/22 10:53
#include <bits/stdc++.h>
using namespace std;

string s;

signed main() {
    cin >> s;
    string t(s.size(), ' ');
    reverse_copy(s.begin(), s.end(), t.begin()); // 反转用于 find
    int res = 0, l = s.find('['), r = s.size() - 1 - t.find(']'); // 找 '['、']'
    // cout << l << ' ' << r << '\n';
    if (r == -1 || l == -1 || r - l < 3) return cout << -1, 0;
    l++, r--;
    while (l <= r && s[l] != ':') l++;
    while (l <= r && s[r] != ':') r--;
    // 找两个 ':'
    // cout << l << ' ' << r << '\n';
    if (r - l < 1) return cout << -1, 0;
    while (l <= r)
        if (s[l++] == '|') res++;
    cout << res + 4;
}

WA on Test#29,输入数据太长 CF 只给了前一小段,如下:

[::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::...

答案:4,输出:-1。是 STL 哪里 G 了吗??

2023/4/22 10:53
加载中...