现在的位置: 首页 > 综合 > 正文

uestc OJ1846 Angry Grammar Nazi

2018年02月22日 ⁄ 综合 ⁄ 共 2152字 ⁄ 字号 评论关闭

Description

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

#include<stdio.h>
#include<iostream>
#include<string.h>
using namespace std;
int main()
{
   int t,cout,k,j;
   char ch[105][105],str[105],lol[4]="lol";
   scanf("%d",&t);getchar();
   while(t--)
   {
       gets(str);
       k=0;j=0; cout=0;
       int len=strlen(str);
       for(int i=0;i<=len;i++)
       if(str[i]>='a'&&str[i]<='z')
            ch[k][j++]=str[i];
        else
        {
            ch[k][j]='\0';k++; j=0;
            while(str[i+1]==' ') i++;
        }
        for(int i=0;i<k;i++)
        if(!strcmp(ch[i],"u")||!strcmp(ch[i],"ur"))
                    cout+=10;
        else if((!strcmp(ch[i],"would")||!strcmp(ch[i],"should"))&&!strcmp(ch[i+1],"of"))
                    { cout+=10; i++; }
        else
        {
            int e=0;
            for(j=0;ch[i][j]!='\0'&&e<3;j++)
            if(ch[i][j]==lol[e]) e++;
            else e=0;
            if(e==3) cout+=10;
        }
        printf("%d\n",cout);
   }
}

抱歉!评论已关闭.