回文串

#include <iostream>
using namespace std;

int main(int argc, char const *argv[])
{
    int flag = 1;
    char test[5];
    cout << "判断是否为回文串eg:abcba"<<endl; 
    cout << "请输入5个字符:";
    int i=0;
    while(i<5) {
        cin>>test[i];
        i++;
     }   
     char *p = test;
     char *q = test+4;
     for (; p<= test+2;p++)
     {
         if(p!=q){
             if (*p!=*q) {
                 flag = 0;
             }
         }
     }

     if (flag==1)
         cout <<"YES" <<endl;
     else
         cout <<"NO" <<endl;
    return 0;
}

results matching ""

    No results matching ""