hdu1247map+string判断是否子单词出现在字典中

#include <iostream>
#include <string>
#include <map>
using namespace std;
map < string , int > mp;
string str[50005];
int main ()
{
    int n = 0;
    while ( cin >> str[n] ) 
	mp[ str[n++] ] = 1;
    for ( int i = 0; i < n; ++ i )
    {
        unsigned len = str[i].size ();
        for ( unsigned j = 1; j < len; ++ j )
        {
            string s1 ( str[i], 0, j );//0开始长度为j 
            string s2 ( str[i], j );//初始位置在j 
            if ( mp[s1] == 1 && mp[s2] == 1 )
            {
                cout << str[i] << endl;
                break;
            }
        }
    }
    return 0;
}


你可能感兴趣的:(String,include)