hdu 5007 Post Robot 水题 2014 ACM/ICPC Asia Regional Xi'an Online

来源:互联网 发布:js获取style 编辑:程序博客网 时间:2024/05/01 12:24

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5007


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 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!
 

Source
2014 ACM/ICPC Asia Regional Xi'an Online


下面的代码有问题,不过数据太水了,所以A了....

#include <algorithm>#include <cstdlib>#include <iostream>#include <cstring>#include <cstdio>#include <vector>#include <cctype>#include <cmath>#include <stack>#include <queue>#include <list>#include <map>#include <set>using namespace std;#define min2(x, y)     min(x, y)#define max2(x, y)     max(x, y)#define min3(x, y, z)  min(x, min(y, z))#define max3(x, y, z)  max3(x, max(y, z))#define clr(x, y)      memset(x, y, sizeof(x))#define fr(i,n)        for(int i = 0; i < n; i++)#define fr1(i,n)       for(int i = 1; i < n; i++)#define upfr(i,j,n)    for(int i = j; i <= n; i++)#define dowfr(i,j,n)   for(int i = n; i >= j; i--)#define scf(n)         scanf("%d", &n)#define ptf(n)         printf("%d",n)#define ptfs(s)        printf("%s",s)#define ptln()         printf("\n")#define srt(a,n)       sort(a,n)#define LL long long#define pi acos(-1.0)#define inf 1 << 31-1#define eps 0.00001#define maxn 100005int main(){    string s;    while(cin >> s)    {        if(s.find("Apple",0)!=-1 || s.find("iPhone",0)!=-1 ||s.find("iPod",0)!=-1 ||s.find("iPad",0)!=-1 )            cout << "MAI MAI MAI!" <<endl;        if(s.find("Sony",0)!= -1)            cout << "SONY DAFA IS GOOD!" << endl;    }    return 0;}


正确姿势:

#include <algorithm>#include <cstdlib>#include <iostream>#include <cstring>#include <cstdio>#include <vector>#include <cctype>#include <cmath>#include <stack>#include <queue>#include <list>#include <map>#include <set>using namespace std;#define min2(x, y)     min(x, y)#define max2(x, y)     max(x, y)#define min3(x, y, z)  min(x, min(y, z))#define max3(x, y, z)  max3(x, max(y, z))#define clr(x, y)      memset(x, y, sizeof(x))#define fr(i,n)        for(int i = 0; i < n; i++)#define fr1(i,n)       for(int i = 1; i < n; i++)#define upfr(i,j,n)    for(int i = j; i <= n; i++)#define dowfr(i,j,n)   for(int i = n; i >= j; i--)#define scf(n)         scanf("%d", &n)#define ptf(n)         printf("%d",n)#define ptfs(s)        printf("%s",s)#define ptln()         printf("\n")#define srt(a,n)       sort(a,n)#define LL long long#define pi acos(-1.0)#define inf 1 << 31-1#define eps 0.00001#define maxn 100005int main(){    //freopen("in.txt", "r", stdin);    string s;    while(cin >> s)    {        int len = s.length();        fr(i, len)        {            string ss = "";            ss += s[i];            if(i + 1 < len)            ss += s[i + 1];            if(i + 2 < len)            ss += s[i + 2];            if(i + 3 < len)            ss += s[i + 3];            if(ss == "iPad" || ss == "iPod")                cout << "MAI MAI MAI!"<< endl;            else if(ss == "Sony")                cout << "SONY DAFA IS GOOD!" <<endl;            else            {                if(i + 4 < len)                ss += s[i + 4];                if(ss == "Apple")                    cout << "MAI MAI MAI!"<< endl;                else                {                    if(i + 5 < len)                    ss += s[i + 5];                    if(ss == "iPhone")                        cout << "MAI MAI MAI!"<< endl;                }            }        }    }    return 0;}



0 0
原创粉丝点击