Problem Description:
What is a palindrome? Like, Aha, Adda, single ahah is not a palindrome, and so on.
How to tell if a string is a palindrome?
The idea here is that we use the queue method to find the middle position of the character, put all the intermediate characters before the stack, and then all out of the stack, and the characters after the middle character to compare, if all the same, then it is a palindrome.
Code:
#include <iostream>#include<queue>#include<string.h>using namespacestd;intMain () {CharStr[] ="Ahaha"; Chartmp[Ten] = {0}; intMiddle =sizeof(str)/sizeof(Char) /2-1 ; Queue<Char>Str_queue; for(inti = middle-1; I >=0; i--) {Str_queue.push (str[i]); } inti =0; while(!Str_queue.empty ()) {Tmp[i]=Str_queue.front (); Str_queue.pop (); I++; } Tmp[i]=' /'; if(MEMCMP (str+3Tmp2) ==0) {cout<<"Yes"<<Endl; } Else{cout<<"No"<<Endl; }}
One-day algorithm: Palindrome judgment