BNU33647:Angry Grammar Nazi

Your friend is what we can call a grammar nazi. He spends a lot of time on popular internet discussion forums. Unfortunately, he has a bad temper and loses his mind whenever someone incorrigibly befouls the English language, with unrelenting violations of grammatical and ortographic rules.
In order to avoid smashed keyboards,monitors and co ee-cup holders, you advice your friend to momentarily stop reading and count to ten each time he becomes angry, instead of smashing something.
Your friend becomes angry whenever he reads the following words or sequences of words:
-- "u", "ur" instead or "you", "your".
-- "would of", "should of" instead of "would have", "should have".
-- "lol" instead of "haha". In fact he becomes angry even when a word contains "lol"as a substring. (Even if a word contains multiple occurrences of "lol", such as the word "lolol", he will only become angry once.)
You decide to write a computer program that reads sentences one by one, and for each sentence calculates how many times your friend will have uttered a number after reading said sentence. Your friend does not read out loud, so numbers that are part of the input-sentences should not be counted.

Input

The first line of the input consists of a single integer T, the number of test cases. The following T lines each contain one sentence; that is, one or more words separated by space.

 0 < T <= 50
 A sentence consists of at most 100 characters, including spaces.
 A word consists only of lower case letters between a and z, inclusively.
 Two adjacent words are separated by exactly one space, and a sentence never has leading or trailing spaces.

Output

For each test case, output how many times your friend have said a number after reading the sentence.

Sample Input

4
u haz lolcats
my car is green
i have a lollipop
u should of lold

Sample Output

20
0
10
30

 

单词是u或者ur,或者单词含有lol,或者含有词组would of,should of,怒气加10

输出怒气

 

#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;

int main()
{
    int n,len,i,ls;
    char str[105];
    char s[105];
    scanf("%d%*c",&n);
    while(n--)
    {
        int ans = 0;
        int flag = 0;
        gets(str);
        len = strlen(str);
        ls = 0;
        str[len] = ' ';
        len++;
        for(i = 0; i<len; i++)
        {
            if(str[i] == ' ' || str[i] == NULL)
            {
                s[ls] = '\0';
                s[ls]=0;
                if (strcmp(s,"u")==0||strcmp(s,"ur")==0) ans++;
                if (strstr(s,"lol")) ans++;
                if (flag&&strcmp(s,"of")==0) ans++;
                if (strcmp(s,"would")==0||strcmp(s,"should")==0)
                    flag = 1;
                else flag = 0;
                ls = 0;
            }
            else
                s[ls++] = str[i];
        }
        printf("%d\n",ans*10);
    }

    return 0;
}


 

你可能感兴趣的:(水,BNU)