http://acm.pku.edu.cn/JudgeOnline/problem?id=3672 此题意思为:在时间允许范围内,走一个来回,最远能走多远 #include<stdio.h> int main() { long m,t,i,sum,temp; int u,f,d; char c; while(scanf("%ld%ld%d%d%d",&m,&t,&u,&f,&d)!=EOF) { sum=0; for(i=0;i<t;i++) { scanf("/n%c",&c); /*去回车,在用scanf()输入单个字符时要去空格或回车*/ if(sum<=m) { temp=i; if(c=='u'||c=='d') sum+=u+d; else if(c=='f') sum+=2*f; } } printf("%ld/n",temp); } return 0; }