求公共后缀
#include<iostream>
#include<string>
#include<vector>
#pragma warning(disable:4996)
using namespace std;
int main()
{
int N;
cin >> N;
getchar();
string resault;
vector<string> f(N);
for (int t = 0;t < N;t++)
getline(cin, f[t]);
int flag = 1,fg=1;//fg:f中是否变空的标志 flag:最后个字符出现不一样的标志
while (1)
{
if (flag == 1 &&fg==1) {
char c = f[0][f[0].size() - 1];
for (auto &x : f)
{
if (x.size() == 1) fg = 0;
if (c == x[x.size() - 1])
{
x.erase(x.size() - 1, 1);
continue;
}
else
{
flag = 0;
break;
}
}
if (flag == 1) resault = c + resault;
}
else break;
}
if (resault.empty())cout << "nai" << endl;
else cout << resault << endl;
}