判断字符串是否为“中心对称”的算法

来源:互联网 发布:mysql error 2002 编辑:程序博客网 时间:2024/04/27 16:12
 

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

#define MAXNUM 100

bool IsSymmetrical(char *a,int n)
{
 cout<<a<<endl<<n<<endl;
 char temp[MAXNUM];
 int i=0,j=0;
 while(i< n/2)
 {
  temp[i] = a[i];
  i++;
 }
 j=i;
 j--;
 cout<<j<<endl;
 if(n%2 != 0)
  i++;
 while(temp[j] == a[i] && i< n)
 {
  j--;
  i++;
 }
 if(i == n)
  return true;
 else
  return false;

}

void main()
{
 char *a = "abcccbb";
 int n = strlen(a);
 bool temp = IsSymmetrical(a,n);
 if(temp == false)
  cout<<"数组a不是中心对称的"<<endl;
 else
  cout<<"数组a是中心对称的"<<endl;
}

 

原创粉丝点击