Decription:
"Palindrome" means a word or phrase such as "deed" or "level", which is the same when you read it backwards. Our task here is not to identify palindromes, because it is too easy a job.
Considering a common word, we can add some letters to its end to make it become a "palindrome-like" string. For example, we can append letter "a" and "c" to the word "cat" and make up a "palindrome-like" string "catac". We can also add more letters to make it become "catitac", but it is longer than "catac".
Your task is to output a shortest "palindrome-like" string base on a given word. Be aware of that you are only allowed to add letters to the end of the given word.
Input
The input consists of some test cases. Each test case starts with a line containing a positive integer n (n <= 10) indicating the number of test cases. This is followed by n lines and each line contains a word which consists of only lowercase letters.
Output
For each case, print the shortest palindrome-like string in a single line without any white spaces or other unnecessary characters.
Sample Input
3
cat
deed
here
Sample Output
catac
deed
hereh
程序:
#include<iostream>
#include<string>
#include<vector>
using namespace std;
void Palindrome(string &S_str)
{
string C_str;
int Sp = 0;
int Cp = 0;
for(int i = S_str.size()-1;i>=0;i--) //倒叙
{
C_str += S_str[i];
}
for(Sp = 0;Sp<S_str.size();Sp++)
{
if(S_str[Sp] == C_str[Cp])
{
Cp++;
}
else
{
if(Cp>0)
Cp--;
}
}
if(Cp != C_str.size())
S_str += C_str.substr(Cp,C_str.size()-1);
}
void main()
{
int lines;
string test;
cin>>lines;
vector<string>Answer;
for(int i = 0; i<lines;i++)
{
cin>>test;
Palindrome(test);
Answer.push_back(test);
}
for(i = 0;i<Answer.size();i++)
{
cout<<Answer[i]<<endl;
}
}