自爆魂

博客园 首页 新随笔 联系 订阅 管理

http://acm.hdu.edu.cn/showproblem.php?pid=5007

字符串处理

暴力

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <queue>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
#define RD(x) scanf("%d",&x)
#define RD2(x,y) scanf("%d%d",&x,&y)
#define clr0(x) memset(x,0,sizeof(x))

typedef long long LL;
char s[40000];
int n;
int main(){
//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);
    //cout<<(8*1024*4);
    char a[10] = "Apple",b[10] = "iPhone",c[10] = "iPod",d[10] = "iPad",e[10] = "Sony";
    while(scanf("%s",s)!=EOF){
        n = strlen(s);
        for(int i = 0;i < n;){
            if(s[i] == 'A' && i + 4 < n){
                if(s[i+1] == 'p' && s[i+2] == 'p' && s[i+3] == 'l' && s[i + 4] == 'e'){
                    puts("MAI MAI MAI!");
                    i = i + 5;
                }
                else
                    ++i;
            }
            else if(s[i] == 'S' && i + 3 < n){
                if(s[i+1] == 'o' && s[i+2] == 'n' && s[i+3] == 'y'){
                    puts("SONY DAFA IS GOOD!");
                    i = i + 5;
                }
                else
                    ++i;
            }
            else if(s[i] == 'i' && i+1 < n && s[i+1] == 'P'){
                bool flag = false;
                if(i+3 < n && s[i+3] == 'd')
                    if(s[i+2] == 'o' || s[i+2] == 'a'){
                        puts("MAI MAI MAI!");
                        i = i + 3;
                        flag = true;
                    }
                if(i + 5 < n && s[i+2] == 'h' && s[i+3] == 'o' && s[i + 4] == 'n' && s[i+5] == 'e'){
                    puts("MAI MAI MAI!");
                    i = i + 4;
                    flag = true;
                }
                if(!flag)
                    ++i;
            }
            else    ++i;
        }
    }
    return 0;
}


posted on 2014-10-15 19:33  自爆魂  阅读(167)  评论(0编辑  收藏  举报