找规律......
AC代码如下:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
using namespace std;
char s[1000001];
int main(){
int T, count, flag, length;
cin >> T;
while( T-- ){
cin >> s;
flag = 0;
count = 0;
length = strlen( s );
if( s[0] != 'M' ){
cout << "No" << endl;
continue;
}
for( int i = 1; i < length; i++ ){
if( s[i] == 'M' ){
flag = 1;
break;
}else if( s[i] == 'I' ){
count++;
}else{
count += 3;
}
}
if( flag == 1 || ( count % 2 == 1 && count != 1 ) || count % 6 == 0 ){
cout << "No" << endl;
}else{
cout << "Yes" << endl;
}
}
return 0;
}