比赛 |
4043级2023省选模拟赛5 |
评测结果 |
AAAAAAAAAAA |
题目名称 |
Moo Operations |
最终得分 |
100 |
用户昵称 |
遥时_彼方 |
运行时间 |
0.000 s |
代码语言 |
C++ |
内存使用 |
0.00 MiB |
提交时间 |
2023-03-27 19:44:05 |
显示代码纯文本
#include<bits/stdc++.h>
#define rep(x,y,z) for(int x=y;x<=z;x++)
#define drep(x,y,z) for(int x=y;x>=z;x--)
#define ull unsigned long long
#define ll long long
using namespace std;
inline int read()
{
int x=0;bool flag=1;char ch=getchar();
while(ch<'0'||ch>'9') {if(ch=='-')flag=0;ch=getchar();}
while(ch>='0'&&ch<='9') {x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
if(flag) return x;
return ~(x-1);
}
inline void write(int x)
{
if(x<0) {x=~(x-1);putchar('-');}
if(x>9) write(x/10);
putchar(x%10+'0');
}
////////////////////////
int nc;
string a;
int main()
{
freopen("moocaozuo.in","r",stdin);
freopen("moocaozuo.out","w",stdout);
nc=read();
int ans;
int s1,s2;
rep(i,1,nc)
{
cin>>a;
ans=999999999;
s2=a.length();
rep(i,1,s2-2)
{
s1=2;
if(a[i]=='O')
{
if(a[i-1]=='M') s1--;
if(a[i+1]=='O') s1--;
ans=min(ans,s1);
}
}
if(ans==999999999) cout<<"-1\n";
else cout<<a.length()-3+ans<<endl;
}
return 0;
}