Problem C: 判断回文串

来源:互联网 发布:windows安装python2.7 编辑:程序博客网 时间:2024/05/29 03:57

Description

对于给定的一个字符串,判断是否是回文串。

Input

一个字符串。

Output

如果是一个回文串,则输出YES,否则输出NO。

Sample Input

chinanihc

Sample Output

YES

HINT

注意:


1. 不能使用数组,即程序中不能出现[、]和new。


2. 可以借助vector和stack判断。

Append Code


#include <iostream>#include <stack>#include <queue>using namespace std;int main(){    stack<char> s;    queue<char> q;    char c;    while(cin >> c)    {        s.push(c);        q.push(c);    }    int flag = 1;    while(!s.empty())    {        if(s.top() != q.front())            flag = 0;        s.pop();        q.pop();    }    if(flag)    {        cout << "YES" << endl;    }    else    {        cout << "NO" << endl;    }    return 0;}

原创粉丝点击