HDOJ 5007 Post Robot--2014网络赛西安赛区A题
2014-09-15 11:06
363 查看
题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=5007
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 193 Accepted Submission(s): 164
Problem Description
DT is a big fan of digital products. He writes posts about technological products almost everyday in his blog.
But there is such few comments of his posts that he feels depressed all the day. As his best friend and an excellent programmer, DT asked you to help make his blog look more popular. He is so warm that you have no idea how to refuse. But you are unwilling to
read all of his boring posts word by word. So you decided to write a script to comment below his posts automatically.
After observation, you found words “Apple” appear everywhere in his posts. After your counting, you concluded that “Apple”, “iPhone”, “iPod”, “iPad” are the most high-frequency words in his blog. Once one of these words were read by your smart script, it will
make a comment “MAI MAI MAI!”, and go on reading the post.
In order to make it more funny, you, as a fan of Sony, also want to make some comments about Sony. So you want to add a new rule to the script: make a comment “SONY DAFA IS GOOD!” when “Sony” appears.
Input
A blog article described above, which contains only printable characters(whose ASCII code is between 32 and 127), CR(ASCII code 13, ‘\r’ in C/C++), LF(ASCII code 10, ‘\n’ in C/C++), please process input until EOF. Note all characters are case sensitive.
The size of the article does not exceed 8KB.
Output
Output should contains comments generated by your script, one per line.
Sample Input
Apple bananaiPad lemon ApplepiSony
233
Tim cook is doubi from Apple
iPhoneipad
iPhone30 is so biiiiiiig Microsoft
makes good App.
Sample Output
MAI MAI MAI!
MAI MAI MAI!
MAI MAI MAI!
SONY DAFA IS GOOD!
MAI MAI MAI!
MAI MAI MAI!
MAI MAI MAI!
Source
2014 ACM/ICPC Asia Regional Xi'an Online
题意: 买买买~~ 索尼大法好! 输入一段字符串,每当出现“Apple”, “iPhone”, “iPod”, “iPad” 中的一个词则输出一句 MAI MAI MAI! 每出现一个Sony 则输出一句 SONY DAFA IS GOOD!
题解:简单字符串处理题~~ 拼的是速度&&细心 我的代码不大简洁的样子,待会看看其他人的如何。
AC代码:
Post Robot
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 193 Accepted Submission(s): 164
Problem Description
DT is a big fan of digital products. He writes posts about technological products almost everyday in his blog.
But there is such few comments of his posts that he feels depressed all the day. As his best friend and an excellent programmer, DT asked you to help make his blog look more popular. He is so warm that you have no idea how to refuse. But you are unwilling to
read all of his boring posts word by word. So you decided to write a script to comment below his posts automatically.
After observation, you found words “Apple” appear everywhere in his posts. After your counting, you concluded that “Apple”, “iPhone”, “iPod”, “iPad” are the most high-frequency words in his blog. Once one of these words were read by your smart script, it will
make a comment “MAI MAI MAI!”, and go on reading the post.
In order to make it more funny, you, as a fan of Sony, also want to make some comments about Sony. So you want to add a new rule to the script: make a comment “SONY DAFA IS GOOD!” when “Sony” appears.
Input
A blog article described above, which contains only printable characters(whose ASCII code is between 32 and 127), CR(ASCII code 13, ‘\r’ in C/C++), LF(ASCII code 10, ‘\n’ in C/C++), please process input until EOF. Note all characters are case sensitive.
The size of the article does not exceed 8KB.
Output
Output should contains comments generated by your script, one per line.
Sample Input
Apple bananaiPad lemon ApplepiSony
233
Tim cook is doubi from Apple
iPhoneipad
iPhone30 is so biiiiiiig Microsoft
makes good App.
Sample Output
MAI MAI MAI!
MAI MAI MAI!
MAI MAI MAI!
SONY DAFA IS GOOD!
MAI MAI MAI!
MAI MAI MAI!
MAI MAI MAI!
Source
2014 ACM/ICPC Asia Regional Xi'an Online
题意: 买买买~~ 索尼大法好! 输入一段字符串,每当出现“Apple”, “iPhone”, “iPod”, “iPad” 中的一个词则输出一句 MAI MAI MAI! 每出现一个Sony 则输出一句 SONY DAFA IS GOOD!
题解:简单字符串处理题~~ 拼的是速度&&细心 我的代码不大简洁的样子,待会看看其他人的如何。
AC代码:
#include<iostream> #include<string> #include<algorithm> #define Max 10000 using namespace std; string str,map[]={"Apple","iPhone","iPod","iPad"}; string out[]={"MAI MAI MAI!","SONY DAFA IS GOOD!"}; int outa[Max],outb[Max]; int main(){ while(cin>>str){ int len=str.size(),posa=0,posb=0,temp; for(int k=0;k<4;k++) for(int i=0;i<len;i++){ if((temp=str.find(map[k],i))!=string::npos){ outa[posa++]=temp;i=temp+1; } } for(int i=0;i<len;i++){ if((temp=str.find("Sony",i))!=string::npos){ outb[posb++]=temp;i=temp+1; } } int i=0,j=0; sort(outa,outa+posa); sort(outb,outb+posb); while(i+j<posa+posb){ if(i==posa) { cout<<out[1]<<endl; j++; } else if(j==posb){ cout<<out[0]<<endl; i++; } else if(outa[i]<outb[j]){ cout<<out[0]<<endl;i++; } else { cout<<out[1]<<endl;j++; } } } return 0; }
相关文章推荐
- HDOJ 5012 Dice--2014网络赛西安赛区F题
- HDU5007-Post Robot-2014西安网络赛(字符串水题)
- HDU 5007 Post Robot KMP (ICPC西安赛区网络预选赛 1001)
- 2014 西安赛区网络赛 5012Dice
- 2014 ACM/ICPC 西安赛区网络赛解题报告汇总
- hdu 5007 Post Robot 水题 2014 ACM/ICPC Asia Regional Xi'an Online
- 2014网络赛 西安赛区
- 2014亚洲区域赛网络赛广州赛区A Corrupt Mayor's Performance Art(hdoj5023)
- 2014西安赛区网络赛 5014 Number Sequence
- hdu 2014西安赛区网络赛 5011Game
- 2014西安赛区网络赛
- 2014 网选 5007 Post Robot(暴力或者AC_自动机(有点小题大作了))
- ZOJ 3814 / 2014 牡丹江赛区网络赛 F. Sawtooth Puzzle
- HDU/HDOJ 4038 2011成都赛区网络赛H题
- ZOJ 3811 / 2014 牡丹江赛区网络赛 C. Untrusted Patrol
- 2014西安网络预选赛1009(矩阵快速幂)hdu5015
- hdu5008 西安赛区网络赛 B题
- 2014西安网络预选赛1002(后缀数组求第K大的子串)hdu5008
- hdu5008 Boring String Problem,2014西安网络赛B题,后缀数组,RMQ
- 矩阵快速幂(2014西安网络赛)+hdu5015