首页 > 其他 > 详细

hdu 1247 Hat’s Words

时间:2015-05-04 20:03:30      阅读:256      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!