UESTC 1846Angry Grammar Nazi 字符串

来源:互联网 发布:淘宝客服回复质量问题 编辑:程序博客网 时间:2024/06/05 04:21

         比赛时队友一遍AC了,但事实上这个题通过率只有20.3%,比赛结束后我竟然是WA2次,RTE2次,第一次没有读好题,对于"u"  "ur" "should of"  "would of"  的判断是以单词的形式,而"lol"是只要在一个单词中出现就可以,例如lolal,这样,还有lolalol这样的只是算作1次。总之,字符串的题目还是弱项!

       #include<cstdio>#include<cstring>using namespace std;int main(){    //freopen("in.txt","r",stdin);    int cas,i,j,sum,len,flagl;    char sen[110],word[110];    scanf("%d\n",&cas);    while(cas--)    {        sum=0;        fgets(sen,110,stdin);        len=strlen(sen)-1;        i=0;        while(1)        {            int g=0;            for(; sen[i]!=' '&&sen[i]!='\n'; i++)                word[g++]=sen[i];            word[g]='\0';            if(strcmp(word,"would")==0||strcmp("should",word)==0)            {                if(i+3<=len&&sen[i+1]=='o'&&sen[i+2]=='f'&&(sen[i+3]==' '||sen[i+3]=='\n'))                {                    sum++;                    i+=3;                    continue;                }            }            if(strcmp(word,"u")==0||strcmp(word,"ur")==0)            sum++;            flagl=0;            for(j=0; j<g; j++)            {                if(g-j>=3&&word[j]=='l'&&word[j+1]=='o'&&word[j+2]=='l'&&!flagl)                {                    sum++;                    flagl=1;                }            }            if(sen[i]!='\n')                i++;            else break;        }        printf("%d\n",sum*10);    }    return 0;}     


原创粉丝点击