用栈判断回文

来源:互联网 发布:淘宝刷单被骗案例 编辑:程序博客网 时间:2024/06/13 06:55
#include<iostream>#include<string>using namespace std;int main() {string a;char s[100];int min, next, top,len,mid;cin >> a;len = a.length();//求字符串的长度mid = len / 2;//中间断开的位置top = 0;for (int i = 0; i < mid; i++) {s[++top] = a[i];//把前半部分加到栈中}if (len % 2 == 0)//判断后半部分开始的位置next = mid;elsenext = mid + 1;for (int i = next; i < len; i++) {if (a[i] != s[top])//判断是否为回文break;top--;}if (top == 0)cout << "yes";elsecout << "no";return 0;}

1 0