Problem E: 判断回文串
Description:
对于给定的一个字符串,判断是否是回文串。Input一个字符串。Output如果是一个回文串,则输出YES,否则输出NO。
Sample Input:
chinanihc
Sample Output:
YES
HINT注意:
-
不能使用数组,即程序中不能出现[、]和new。
-
可以借助vector和stack判断。
#include <iostream>
#include <vector>
#include <stack>
using namespace std;
int main()
{
stack<char> sta;
vector<char> vec;
char c;
while(cin>>c)
{
sta.push(c);
vec.push_back(c);
}
int l=vec.size();
int p=1;
for(int i=0;i<l;i++)
{
if(vec.front()!=sta.top())
{
p=0;
break;
}
vec.erase(vec.begin(),vec.begin()+1);
sta.pop();
}
if(p)
cout<<"YES";
else
cout<<"NO";
return 0;
}