64,439
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <algorithm>
#include <string>
#include <functional>
const int MAX = 110;
using namespace std;
string Rev(string s);
int main()
{
int tCase;
string str[MAX];
cin >> tCase;
while(tCase--)
{
int Cas,len;
int j_used; //加
string sRecord;
cin >> Cas;
len = MAX;
for(int i=0; i<Cas; ++i)
{
cin >> str[i];
if(str[i].size() <= len)
{
len = str[i].size();
sRecord = str[i];
j_used=i; //记录被比较的字符串下标
}
}
while(len)
{
for(int k=0; k<sRecord.size()-len+1; ++k)
{
bool mark = true;
string str1,str2;
str1 = sRecord.substr(k,len);
str2 = Rev(str1);
for(int j=0; j<Cas; ++j)
{
if (j==j_used) continue; //排除被比较的字符串
if(string::npos == str[j].find(str1) && string::npos == str[j].find(str2))
{
mark=false;
break;
}
}
if (mark) goto end;
}
len--;
}
end: cout << len << endl;
}
return 0;
}
string Rev(string s)
{
string rs;
for(int i=s.size()-1; i>=0; --i)
{
rs += s[i];
}
return rs;
}
#include <iostream>
#include <algorithm>
#include <string>
#include <functional>
const int MAX = 110;
using namespace std;
string Rev(string s);
int main()
{
int tCase;
string str[MAX];
cin >> tCase;
while(tCase--)
{
int Cas,len;
int j_used, max_len=0; //加
string sRecord;
cin >> Cas;
len = MAX;
for(int i=0; i<Cas; ++i)
{
cin >> str[i];
if(str[i].size() <= len)
{
len = str[i].size();
sRecord = str[i];
j_used=i; //记录被比较的字符串下标
}
}
while(len)
{
bool mark = false;
for(int k=0; k<sRecord.size()-len+1; ++k)
{
string str1,str2;
str1 = sRecord.substr(k,len);
for(int j=0; j<Cas; ++j)
{
if (j==j_used) continue; //排除被比较的字符串
str2 = Rev(str[j]);
if(string::npos != str[j].find(str1)
|| string::npos != str2.find(str1)) //错 && string::npos != str2.find(str1))
{
//mark = true;
if (max_len < len) max_len = len; //记录最大的长度
}
//if(mark) goto end;
}
}
len--;
}
cout << max_len << endl;//end: cout << len << endl;
}
return 0;
}
string Rev(string s)
{
string rs;
for(int i=s.size()-1; i>=0; --i)
{
rs += s[i];
}
return rs;
}