uestc OJ1846 Angry Grammar Nazi
来源:互联网 发布:零基础自学日语 知乎 编辑:程序博客网 时间:2024/06/05 15:16
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); }}
- uestc OJ1846 Angry Grammar Nazi
- UESTC 1846Angry Grammar Nazi 字符串
- Angry Grammar Nazi
- BNU33647:Angry Grammar Nazi
- Angry Grammar Nazi
- Angry Grammar Nazi (水)
- IDIOPEN 2013 A Angry Grammar Nazi(字符串处理)
- UESTC
- UESTC
- UESTC
- UESTC
- UESTC
- UESTC
- UESTC
- UESTC
- UESTC
- UESTC
- UESTC
- 数组的操作--奇偶反转
- 类名.this与类名.class
- Windows安装memcached图文教程
- 一位电子工程师的话
- virtualbox,kvm性能比较
- uestc OJ1846 Angry Grammar Nazi
- hdu 4405 Aeroplane chess
- 嵌入式linux课程
- poj1311数制转换
- LeetCode_Single Number II
- N个通信兵的问题
- 线程回顾第二篇:传统定时器
- Big Data, Apple Driving Industry's Biggest Salaries
- html5 视频和音乐播放器标签属性