AcWing 779. 最长公共字符串后缀
原题链接
困难
作者:
STU756
,
2021-01-20 17:05:26
,
所有人可见
,
阅读 301
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
const int N = 201;
string a[N];
int main(){
int n;
while(cin >> n,n) {
int max = 201;
string s, a;
cin >> s;
for(int i = 1; i < n; i++) {
cin >> a;
int res = 0;
for(int j = 0; j < a.size() && j < s.size(); j++) {
if(a[a.size()- 1- j] == s[s.size() - 1 -j]) ++res;
else break;
}
max = min(max, res);
}
if(max) cout << s.substr(s.size() - max) << endl;
else cout << endl;
}
return 0;
}