HDU 5007-Post Robot(字符串)
来源:互联网 发布:plsql写sql时中文乱码 编辑:程序博客网 时间:2024/09/21 06:35
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.
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.
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 ApplepiSony233Tim cook is doubi from AppleiPhoneipadiPhone30 is so biiiiiiig Microsoftmakes 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!
思路:字符串匹配,使用 substr;
s.substr() :返回整条字符串。
s.substr(i, len):返回从索引i 截取长度len 的子串。
CODE:
#include <iostream>#include <cstdio>#include <algorithm>#include <cmath>#include <string>#include <cstring>#include <queue>#include <stack>#include <vector>#include <set>#include <map>const int inf=0xfffffff;typedef long long ll;using namespace std;string s;int main(){ //freopen("in", "r", stdin); string a="Apple",b="iPhone", c="iPod", d="iPad",e="Sony"; while(getline(cin,s)){ //cout <<s<<endl; int len = s.length(); for(int i = 0 ; i < s.size(); i ++){ if(s.substr(i, 5) == a.substr() ){ printf("MAI MAI MAI!\n"); i += 4; } if(s.substr(i, 6) == b.substr() ){ printf("MAI MAI MAI!\n"); i += 5; } if(s.substr(i,4) == c.substr() || s.substr(i,4) == d.substr()){ printf("MAI MAI MAI!\n"); i += 3; } if(s.substr(i,4) == e.substr()){ printf("SONY DAFA IS GOOD!\n"); i += 3; } } //s.clear(); } return 0;}
0 0
- HDU 5007 Post Robot(字符串寻找)
- HDU 5007-Post Robot(字符串)
- 字符串水题 hdu 5007 Post Robot
- HDU - 5007 Post Robot
- hdu 5007 Post Robot
- hdu 5007 Post Robot
- hdu 5007 Post Robot
- hdu 5007 Post Robot
- HDU-#5007 Post Robot(暴力)
- hdu 5007 Post Robot 水题
- hdu 5007 Post Robot(水题)
- Post Robot(字符串匹配)
- HDU 5007 Post Robot(西安网络赛A题)
- HDU——5007 Post Robot
- hdu 5007 Post Robot【模拟】水题
- HDU5007 Post Robot(字符串处理)
- HDOJ 5007 Post Robot
- Post Robot(模拟)
- struts2 一般开发流程
- struts2 标签
- struts2 OGNL表达式
- struts2 valuestack
- 属性2
- HDU 5007-Post Robot(字符串)
- 图形学中的贴图采样、走样与反走样等
- 海康ps流转换h264流
- 复合
- C语言个人代码总结(下)
- 开环单位增益带宽 , 与-3db的关系
- LeetCode Palindrome Partitioning
- 36 Request对象 Session Application
- [微积分] 常用定义与公式