利用反转函数确定回文串

时间:2022-07-24
本文章向大家介绍利用反转函数确定回文串,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

题意:给出一个字符串,然后让你判断是否为回文串,是得话输出YES,否则输出NO

思路:我们可以直接利用string 跟 reverse()函数解决这个问题

#include<bits/stdc++.h>

using namespace std;

int  judge(string &s){
	string temp = s;
	reverse(temp.begin(),temp.end());
	return temp == s;
}


int main(){
	int t;
	cin>>t;
	while(t--){
	  string s;
	  cin>>s;
	  if(judge(s)) cout<<"YES"<<endl;
	  else{
	  	cout<<"NO"<<endl;
	  }	
	}
	return 0;
}