码迷,mamicode.com
首页 > 其他好文 > 详细

hdu 1247 Hat’s Words

时间:2015-05-04 20:04:31      阅读:112      评论:0      收藏:0      [点我收藏+]

标签:

map水过去了,240ms的样子。。。用字典树应该比map快多了吧。

#include<stdio.h>
#include<string.h>
#include<math.h>
#include<map>
#include<algorithm>
using namespace std;
map<string, int> abc;
char s[50005][1000];
int main()
{
    char k[1000];
    abc.clear();
    int tot = 0;
    while (~scanf("%s", k))
    {
        abc[k] = 1;
        strcpy(s[tot], k);
        tot++;
    }
    int i, j;
    for (i = 0; i < tot; i++)
    {
        for (j = 1; j <= strlen(s[i]) - 1; j++)
        {
            char temp1[50] = { \0 };
            char temp2[50] = { \0 };
            strncpy(temp1, s[i], j);
            strncpy(temp2, s[i] + j, strlen(s[i]) - j);
            if (abc[temp1] == 1 && abc[temp2])
            {
                printf("%s\n", s[i]);
                break; 
            }
        }
    }
    return 0;
}

 

hdu 1247 Hat’s Words

标签:

原文地址:http://www.cnblogs.com/zufezzt/p/4476982.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!