2017青岛网赛 C - The Dominator of Strings

1

Here you have a set of strings. A dominator is a string of the set dominating all strings else. The string  SS is dominated by  TT if  SS is a substring of  TT.
InputThe input contains several test cases and the first line provides the total number of cases. 
For each test case, the first line contains an integer  NN indicating the size of the set. 
Each of the following  NN lines describes a string of the set in lowercase. 
The total length of strings in each case has the limit of  100000
The limit is 30MB for the input file. OutputFor each test case, output a dominator if exist, or No if not. Sample Input
3
10
you
better
worse
richer
poorer
sickness
health
death
faithfulness
youbemyweddedwifebetterworsericherpoorersicknesshealthtilldeathdouspartandpledgeyoumyfaithfulness
5
abc
cde
abcde
abcde
bcde
3
aaaaa
aaaab
aaaac
Sample Output
youbemyweddedwifebetterworsericherpoorersicknesshealthtilldeathdouspartandpledgeyoumyfaithfulness
abcde
No

题目大意: 给你 n 个字符串,让你输出其中一个字符串,这个字符串包含所有其他的字符串。如果没有,输出 No ;

字符串的长度小于100000,个数 n 没有范围,但输入的总量 不超过 30Mb。

思路:由于n不确定,所以可以用vector 来存放字符串。(set也可以,但是由于他会在容器中排序,所以时间会多一点)。


代码:

#include
#include
#include
#include
#include
using namespace std;
vector st;

int main ()
{
	std::cin.sync_with_stdio(false);
	int T;
	cin>>T;
	while(T--)
	{
		int n,i,mxlen=-1,bj=0;
		string mx;
		st.clear();
		cin>>n;
		for(i=0;i>s;
			st.push_back(s);
		}
		for(vector::iterator it=st.begin();it!=st.end();it++)
		{
			int tmp;
			tmp=(*it).length();
			if(tmp>mxlen)
			{
				mxlen=tmp;
				mx=*it;
			}
		}	
		for(vector::iterator it=st.begin();it!=st.end();it++)
		{
			int tmp,j,k;
			tmp=(*it).length();
			if(tmp==mxlen)
			{
				if(*it!=mx)
				{
					bj++;
				}
			}
			if(mx.find(*it)==string::npos)
				bj++;
			if(bj!=0)
			{
				cout<<"No"<


你可能感兴趣的:(2017青岛网赛 C - The Dominator of Strings)