
这个问题可以通过计数来解决。对于每个case,我们可以计算出F和M的数量。如果F和M的数量相等,那么就可以形成一个环,否则就不能。
以下是一个C++的解决方案:
#include <iostream>
#include <string>
using namespace std;
int main() {
    int T;
    cin >> T;
    cin.ignore();
    while (T--) {
        string s;
        getline(cin, s);
        int F = 0, M = 0;
        for (char c : s) {
            if (c == 'F') F++;
            else if (c == 'M') M++;
        }
        if (F == M) cout << "LOOP" << endl;
        else cout << "NO LOOP" << endl;
    }
    return 0;
}这段代码首先读取case的数量,然后对于每个case,它读取长条的描述,并计算F和M的数量。如果F和M的数量相等,它就输出"LOOP",否则就输出"NO LOOP"。



















