![在这里插入图片描述](https://img-blog.csdnimg.cn/20190610230743609.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2x4eV96elo=,size_16,color_FFFFFF,t_70)
#include <iostream>
#include <string>
using namespace std;
int main()
{
string str;
while (cin >> str)
{
string ret;
for (int i = 0; i < str.size(); i++)
{
ret.insert(ret.begin(), str[i]);
}
cout << ret.c_str() << endl;
}
return 0;
}
![在这里插入图片描述](https://img-blog.csdnimg.cn/20190610230840361.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2x4eV96elo=,size_16,color_FFFFFF,t_70)
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int fun(string A, string B)
{
int maxlength = 0;
string ret;
for (size_t i = 0; i < B.size(); ++i)
{
for (size_t j = B.size() - i; j > 0; j--)
{
ret = B.substr(i,j);
if (A.find(ret) != string::npos && maxlength < ret.size())
{
maxlength = ret.size();
}
}
}
return maxlength;
}
int main()
{
string str1, str2;
while(cin >> str1 >> str2)
{
int len;
if (str1.size() < str2.size())
len = fun(str2, str1);
else
len = fun(str1,str2);
cout << len << endl;
}
return 0;
}