首页 > 其他 > 详细

回文串判断

时间:2016-08-12 22:00:26      阅读:127      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!