CDOJ--1846
原题链接:http://acm.uestc.edu.cn/problem.php?pid=1846
分析:设置front记录前一个单词即可,容易题。
Angry Grammar Nazi
1 #include<stdio.h> 2 #include<string.h> 3 int lol(char string[105]) 4 { 5 int i,len; 6 len=strlen(string); 7 for(i=0;i<len-2;i++) 8 { 9 if(string[i]=='l'&&string[i+1]=='o'&&string[i+2]=='l')return 1; 10 } 11 return 0; 12 } 13 int main() 14 { 15 int T,i,j,ans,flag,count; 16 char str[105],front[105]; 17 scanf("%d",&T); 18 getchar(); 19 while(T--) 20 { 21 memset(str,0,sizeof(str)); 22 ans=0;flag=0; 23 gets(str); 24 j=0; 25 memset(front,0,sizeof(front)); 26 count=0; 27 for(i=0;;i++) 28 { 29 if(str[i]>='a'&&str[i]<='z') 30 front[j++]=str[i]; 31 else 32 { 33 count++; 34 front[j]='\0'; 35 if(j==1&&front[0]=='u')ans++; 36 else if(j==2&&strcmp(front,"ur")==0)ans++; 37 else if(strcmp(front,"should")==0||strcmp(front,"would")==0){flag=1;count=0;} 38 else if(strcmp(front,"of")==0&&flag==1&&count==1)ans++; 39 else if(lol(front)==1)ans++; 40 j=0; 41 memset(front,0,sizeof(front)); 42 } 43 if(str[i]=='\0')break; 44 } 45 printf("%d\n",ans*10); 46 } 47 return 0; 48 } 49 50