题目地址
AC代码
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
bool cmp(string a,string b){
for (int i = 0; i < a.length(); ++i) {
if(a[i]==b[i])continue;
else return a[i] < b[i];
}
}
int main() {
ios::sync_with_stdio(false);
int t;
cin>>t;
for (int i = 0; i < t; ++i) {
int n;
cin>>n;
vector<string>list;
vector<string>ans;
for (int j = 0; j < n; ++j) {
string temp;
cin>>temp;
list.push_back(temp);
}
for (int k = 60; k >=3 ; --k) {
int dd=1;
for (int j = 0; j + k <= 60; ++j) {
string sb = list.begin()->substr(j, k);
int boo = 1;
for (vector<string>::iterator it = list.begin() + 1; it != list.end(); it++) {
if (it->find(sb) == string::npos) {
boo = 0;
break;
}
}
if (boo) {
ans.push_back(sb);
dd=0;
}
}
if(dd&&k==3){
cout << "no significant commonalities" << endl;
break;
}else if(dd==0){
sort(ans.begin(),ans.end(),cmp);
cout<<*ans.begin()<<endl;
break;
}
}
}
return 0;
}
题解和题目思路
这道题其实也没什么好讲的,就是纯粹的模拟而已,俗话说的好,能暴力过的就先暴力(滑稽)不行的再认真想,万一就过了呢