码迷,mamicode.com
首页 > 其他好文 > 详细

回文串判断

时间:2016-08-12 22:01:09      阅读:125      评论:0      收藏:0      [点我收藏+]

标签:回文串

 
#include <bits/stdc++.h>
using namespace std;
  
int judge_palindrome(string s) 
{  
     string tmp=s;   
     std::reverse(tmp.begin(), tmp.end());   //tmp 和 t 是  s的翻转
     string t(tmp);                          //构造新串 t
                                  // return !!t.compare(s);                 //和原串进行比较
     return t==s;
} 
int main()
{
      string s="goog";
      if(judge_palindrome(s)) cout<<" 是回文串"<<endl;
      else                     cout<<" 不 是回文串 "<<endl;
    
    return 0;
}

string 对象下的系列函数学习

回文串判断

标签:回文串

原文地址:http://wzsts.blog.51cto.com/10251779/1837301

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!