AcWing 779. 最长公共字符串后缀
原题链接
困难
作者:
Woo
,
2021-05-05 10:23:50
,
所有人可见
,
阅读 218
代码
#include <iostream>
#include <string>
using namespace std;
int main()
{
int n;
while(cin >> n && n != 0)
{
string s[n];
for(int i = 0; i < n; i ++)
{
cin >> s[i];
}
int res1 = 200;
for(int i = 1; i < n; i ++)
{
int res2 = 0;
for(int j = 1; j <= s[i].size(); j ++)
{
if(s[i][s[i].size() - j] == s[i - 1][s[i - 1].size() - j]) res2 ++;
}
if(res2 < res1) res1 = res2;
}
if(res1 == 0) cout << endl;
else cout << s[0].substr(s[0].size() - res1, res1) << endl;
}
return 0;
}