bnuoj 33647 Angry Grammar Nazi(字符串)

http://www.bnuoj.com/bnuoj/problem_show.php?pid=33647

【题意】:字符串匹配,暴力配就行了

【题解】:截出单词,然后进行匹配就行了

【code】:

 1 #include <iostream>
 2 #include <stdio.h>
 3 #include <string.h>
 4 #include <algorithm>
 5 
 6 using namespace std;
 7 
 8 char tstr[100][100];
 9 
10 int main()
11 {
12     int t;
13     scanf("%d",&t);
14     getchar();
15     while(t--)
16     {
17         char str[1000];
18         char ss[100];
19         gets(str);
20         int len = strlen(str);
21         int i,j=0,k=0,flag=1;
22         for(i=0;i<len;i++)
23         {
24             if(str[i]==' ')
25                 continue;
26             while(i<len)
27             {
28                 tstr[j][k]=str[i];
29               //cout<<str[i];
30                 k++;
31                 i++;
32                 if(i>=len||str[i]==' ')
33                 {
34                     break;
35                 }
36 
37             }
38             tstr[j][k]='';
39             j++;
40             k=0;
41         }
42        // for(i=0;i<j;i++)cout<<tstr[i]<<endl;
43         int size = j;
44         int ans = 0;
45         for(i=0;i<size;i++)
46         {
47             if(strcmp(tstr[i],"u")==0||strcmp(tstr[i],"ur")==0)
48             {
49                 ans++;
50             }
51             else if(strcmp(tstr[i],"should")==0&&i+1<size&&strcmp(tstr[i+1],"of")==0)
52             {
53                 ans++;
54             }
55             else if(strcmp(tstr[i],"would")==0&&i+1<size&&strcmp(tstr[i+1],"of")==0)
56             {
57                 ans++;
58             }
59         }
60      //   cout<<tstr[0]<<endl;
61         for(i=0;i<size;i++)
62         {
63             int len = strlen(tstr[i]);
64             for(j=0;j<len-2;j++)
65             {
66                 if(tstr[i][j]=='l'&&tstr[i][j+1]=='o'&&tstr[i][j+2]=='l')
67                 {
68                     ans++;
69                     break;
70                 }
71             }
72         }
73         printf("%d
",ans*10);
74     }
75     return 0;
76 }
原文地址:https://www.cnblogs.com/crazyapple/p/3352408.html