Sample Input
3
Itai nyan~
Ninjin wa iyadanyan~
uhhh nyan~
Sample Output
nyan~
思路:
找最后有几位会重复,暴力就行。
注意输入。
代码
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <string>
#include <cstring>
#include <vector>
#include <map>
#include <cmath>
#include <set>
using namespace std;
#define endl '\n'
typedef long long ll;
int main()
{
int n;
cin >> n;
string ans = "", b;
getchar();
int f = 0;
for (int i = 1; i <= n; ++i)
{
string s;
getline(cin, s);
if (i == 1)
{
// b = s;
reverse(s.begin(), s.end());
ans = s;
}
else
{
int num = 0;
for (int i = 0; i < ans.size(); ++i)
{
if (ans[i] == s[s.size() - 1 - i])
num++;
else
break;
}
if (num == 0)
{
f = 1;
}
else
{
ans = ans.substr(0, num);
}
}
}
if (f)
cout << "nai" << endl;
else
{
reverse(ans.begin(), ans.end());
cout << ans << endl;
}
// getchar(); getchar();
return 0;
}