回文串----啊哈算法
【摘要】
//
// Created by jal on 18-9-2.
//
#include <bits/stdc++.h>
using namespace std;
bool f(strin...
//
// Created by jal on 18-9-2.
//
#include <bits/stdc++.h>
using namespace std;
bool f(string s){
stack<char> stk;
int len = s.size();
int mid = len/2;
for(int i = 0; i < mid; i++){
stk.push(s[i]);
}
if(len&1){
mid++;
}
for(int i = mid; i < len; i++){
char t = stk.top();
stk.pop();
if(t != s[i]){
return false;
}
}
return true;
}
int main() {
string s1="123454321";
string s2="1234554321";
cout << f(s1) << endl;
cout << f(s2) << endl;
string s3="13454321";
string s4="134554321";
cout << f(s3) << endl;
cout << f(s4) << endl;
}
分别输出 1 1 0 0
文章来源: blog.csdn.net,作者:爱玲姐姐,版权归原作者所有,如需转载,请联系作者。
原文链接:blog.csdn.net/jal517486222/article/details/82315897
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
作者其他文章
评论(0)