题解:P10397 『STA - R5』5k.sync.closer

· · 题解

一道水题,考验字符串操作。

设字符串为 S,我们只需找出 S 中第 1 和第 2 个引号的位置 p_1,p_2,S_{p_1+1 \ldots p_2-1} 便是答案。

#include <iostream>
#include <string>
using namespace std;
int main() {
    int t;
    cin >> t;
    while (t--) {
        string s;
        cin >> s;
        int pos = s.find("\"");
        s.erase(0, pos + 1);
        // cout << s << endl;
        pos = s.find("\"");
        // cout << pos << " ";
        cout << s.substr(0, pos) << endl;
    }
}