AcWing 3700. 女士优先
原题链接
简单
作者:
做梦都ac
,
2023-07-17 10:42:37
,
所有人可见
,
阅读 186
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int main()
{
string str;
cin>>str;
int ptr = 0;
while(str[ptr] == 'F') ptr ++;
str = str.substr(ptr);
int m = 0,f = 0;
int time[100050] = {0};
int cnt = 1;
for(int i = 0;i < str.length();i ++)
{
if(str[i] == 'M') m ++;
else
{
//如果前面女生走的时间,超过了女生前面的所有男生,代表可以追上
//可以追上前面女生的情况,时间为前面女生的时间 + 1
if(time[cnt - 1] >= m)
{
time[cnt] = time[cnt - 1] + 1;
}
else
//如果追不上时间就是前面男生的数量
{
time[cnt] = m ;
}
cnt ++;
}
}
cout<<time[cnt - 1];
}