标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 10993 Accepted Submission(s): 3944
#include<iostream> #include<cstdio> #include<string> #include<map> using namespace std; map<string,int> M; string str[50005]; int main() { //freopen("in.txt", "r", stdin); int k = -1; while(cin>>str[++k]) M[str[k]] = 1; for(int i=0; i<=k; i++) { int len= str[i].size()-1; for(int j=1; j<len; j++) { string s1(str[i], 0, j); string s2(str[i], j); if(M[s1]==1&&M[s2]==1) { cout<<str[i]<<endl; break; } } } return 0; }
本题技巧: string s1(str[i], 0, j);把str[i]中的0~j的字符赋给s1. string s2(str[i], j)把str[i]中的j~末尾的字符赋给s2.
HDU 1247 Hat's Words (map+string)
标签:
原文地址:http://www.cnblogs.com/acm1314/p/4760769.html