HDU 2163 Palindromes

来源:互联网 发布:唱歌培训软件 编辑:程序博客网 时间:2024/05/01 11:00

链接 : http://acm.hdu.edu.cn/showproblem.php?pid=2163


还是判断回文,栈,输入“STOP”时停止


#include <iostream>#include <stdio.h>#include <string.h>#include <stack>using namespace std;int main(){    int k=1;    char str[53];    while(cin>>str,strcmp(str,"STOP"))    {        bool flag=0;        stack<char> s;        int len=strlen(str);        if(len==1)        {            cout<<"#"<<k++<<": YES"<<endl;            continue;        }        if(len%2) flag=1;        for(int i=0; i<len; i++)        {            if(flag && i==len/2) continue;            if(s.empty() || s.top()!=str[i]) s.push(str[i]);            else s.pop();        }        printf(s.empty() ? "#%d: YES\n" : "#%d: NO\n",k++);    }    return 0;}


0 0