Title address
Title: Give you n strings and ask if there is a string. It contains all strings, which is equivalent to all strings being substrings of one of them.
Thoughts: This topic I am trying to hand in, unexpectedly found that even string find function can pass, which makes me particularly surprised, to return to the truth, we can find that the mother string must be the longest one, because it must be the mother string of all strings, and then for the same length, it is necessary that these strings are exactly the same, only in this way can we find out that the mother string is the longest one. Satisfy that condition, and then the other strings will find directly in the parent str (the code is clear)
#include <iostream>
#include <cstring>
#include <string>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#define N 100010
#define M 1000010//double
#define LL long long
#define inf 0x3f3f3f3f
#define lson l,mid,ans<<1
#define rson mid+1,r,ans<<1|1
#define getMid (l+r)>>1
#define movel ans<<1
#define mover ans<<1|1
using namespace std;
const LL mod = 1000000007;
string str[N];
int main() {
cin.sync_with_stdio(false);
int n, T;
int maxid, maxlen;
bool flag;
int len;
cin >> T;
while (T--) {
cin >> n;
maxid = -1;
flag = true;
for (int i = 0; i < n; i++) {
cin >> str[i];
len = str[i].length();
if (maxid == -1 || maxlen < len) {
maxid = i;
maxlen = len;
flag = true;
}
else if (maxlen == len&&str[maxid] != str[i]) {
flag = false;
}
}
if (flag) {
for (int i = 0; i < n; i++) {
if (str[maxid].find(str[i]) == str[i].npos) {
flag = false;
break;
}
}
}
if (flag) {
cout << str[maxid] << endl;
}
else {
cout << "No" << endl;
}
}
return 0;
}