AcWing 779. 最长公共字符串后缀
原题链接
困难
作者:
NeonSean
,
2020-08-15 19:17:07
,
所有人可见
,
阅读 305
#include <iostream>
using namespace std;
int const N = 200;
int n;
string str[N];
int main() {
while (cin >> n, n) {
int len = 1000;
for (int i = 0; i < n; i++) {
cin >> str[i];
if (str[i].size() < len) len = str[i].size();
}
string a, b, c;
while (len) {
for (int j = 1; j < n; j++) {
a = str[0].substr(str[0].size() - len);
b = str[j].substr(str[j].size() - len);
// cout << a << endl;
// cout << b << endl;
if (a != b) {
len--;
break;
}
if (a == b && j == n - 1) {
c = a;
len = 0;
break;
}
}
}
cout << c << endl;
}
return 0;
}