P1003题目
按题意计算即可。
每跑一段,要加上跑过和返回的时间,满足总时间小于要求时间即可。
#include<iostream>
using namespace std;
int t,m,u,f,d,ans=0,tm;
char c;
int main(){
cin>>m>>t>>u>>f>>d;
for(int i=1;i<=t;i++){
cin>>c;
switch(c){
case 'u':
case 'd':
tm+=u+d;
break;
case 'f':
tm+=f+f;
break;
}
if(tm>m){
cout<<ans<<endl;
return 0;
}
ans++;
}
cout<<ans<<endl;
return 0;
}