HDU5007 Post Robot

Post Robot

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

思路:按单词接受,枚举字符的子串然后判断。

#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
const char t[5][10] = {{"Apple"},{"iPhone"}, {"iPod"}, {"iPad"}, {"Sony"} };
const char s1[20] = { "MAI MAI MAI!"}, s2[20] = {"SONY DAFA IS GOOD!"};
int ok(char * s)
{
    if(strcmp(s, t[0]) == 0 || strcmp(s, t[1]) == 0 || strcmp(s, t[2]) == 0 || strcmp(s, t[3]) == 0)
    return 1;
    if(strcmp(s, t[4]) == 0)
    return 2;
    return 0;
}
int main()
{
    //freopen("in.txt", "r", stdin);
    char s[100], c[100];
    while(scanf("%s", s) != EOF)
    {
        int i, j, k, str = strlen(s);
        if(str < 4) continue;

        for(i = 0; i < str - 3; i++)
        {
            for(j = i + 3; j < str; j++)   //bananaiPad
            {
                if((j-i) >= 6) continue;
                int m = 0;
                for(k = i; k <= j; k++)
                {
                    c[m++] = s[k];
                }
                c[m] = '\0';
                if(ok(c) == 1)
                {
                    printf("%s\n", s1);
                    i = j + 1;
                }
                if(ok(c) == 2)
                {
                    printf("%s\n", s2);
                    i = j + 1;
                }
            }
        }
    }
    return 0;
}


posted @ 2014-09-14 18:00  栗子强  阅读(127)  评论(0编辑  收藏  举报