hdu 1251 字典树的应用

这道题看了大神的模板,直接用字典树提交的会爆内存,用stl 里的map有简单有快

#include <iostream>
#include <map>
#include <cstring>
#include <string>
using namespace std;

int main()
{
    int i, len;
    char str[10];
    
    map<string, int> m;
    while( gets(str) )
    {
        len = strlen(str);
        if ( !len )
        {
            break;
        }
        for(i = len; i > 0; i--)
        {
            str[i] = '\0';
            m[str]++;
        }
    }
    while( gets(str) )
    {
        cout << m[str] << endl;
    }
    
    return 0;
}

另附加一篇介绍map的好文章http://www.kuqin.com/cpluspluslib/20071231/3265.html

posted @ 2015-08-26 20:40  超级学渣渣  阅读(168)  评论(0编辑  收藏  举报