AcWing 779. 最长公共字符串后缀
原题链接
简单
作者:
赵珂欣
,
2024-12-04 21:37:31
,
所有人可见
,
阅读 2
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
int n;
while (cin >> n, n)
{
string strs[n];
int min_len = 210;
for (int i = 0; i < n; i ++)
{
string s;
cin >> s;
reverse(s.begin(), s.end());
min_len = min(min_len, (int)s.size());
strs[i] = s;
}
string res;
for (int i = 0; i < min_len; i ++)
{
char c = strs[0][i];
bool flag = true;
for (string s : strs)
if (s[i] != c)
{
flag = false;
break;
}
if (flag) res += c;
else break;
}
reverse(res.begin(), res.end());
cout << res << endl;
}
return 0;
}