【UVA】10391 Compound Words(STL map)

题目

题目
 


分析

自认已经很简洁了,虽说牺牲了一些效率
 


代码

#include <bits/stdc++.h>
using namespace std;
set <string> m;
string s[120003];
int main()
{
	int n;
	while(cin>>s[n]) m.insert(s[n++]);
	for(int i=0;i<n;i++)
	{
		int l=s[i].length();
		for(int j=1;j<l;j++)
			if(m.count(s[i].substr(0,j))&&m.count(s[i].substr(j,l-j)))
			{
				cout<<s[i]<<endl;break;
			}
	}
	return 0;
}
原文地址:https://www.cnblogs.com/noblex/p/7897459.html