[Algorithm] notes judgment judgment is not a palindrome character

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <string.h>
using namespace std;

const int maxn = 256;
bool judge(char str[]){
	int i,len;
	len = strlen(str);
	// ①不用到i==len/2,  ②从0下标开始,i的对应位置是len-1-i;
	for(i=0; i<len/2; i++){
		if(str[i] == str[len-1-i])
			i++;
		else 
			return false;
	}
	return true;
}
int main()
{
	char str[maxn];
	while(gets(str)){
		bool flag = judge(str);
		if(flag == true)
			cout<<"YES"<<endl;
		else
			cout<<"NO"<<endl;
	}

 

Published 63 original articles · won praise 13 · views 40000 +

Guess you like

Origin blog.csdn.net/changreal/article/details/88211720