简体   繁体   English

检查字符串是否为回文

[英]check whether the string is palindrome or not

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int checkpalindrome(char* a,int n);
int main()
{
    char *a;
    int i,n;
    printf("Enter the size of the string but should be odd => ");
    scanf("%d",&n);
    a=(char*)calloc(n,sizeof(char));
    for(i=0;i<n;i++)
    {
        if(i==(n-1)/2)
        {  printf("Enter X\n");}
        scanf("%c",&a[i]);
    }
    if(checkpalindrome(a,n)){
      printf("\nstring is palindrome");
    }
    else{ 
      printf("\nstring is not a palindrome");
    }
    return 0;
}
int checkpalindrome(char *a,int n)
{
    int i;
    for(i=0;i<n;i++)
    {
        if(a[i]==a[n-i])
          continue;
        else
          return 0;
    }
    return 1;
}

check this code i am not getting proper output here the string should be of a's and b's and X should in middle of the string and we have to check whether the string is palindrome or not.检查这段代码我没有得到正确的 output 这里的字符串应该是 a's 和 b's 和 X 应该在字符串的中间,我们必须检查字符串是否是回文。

If you want to implement two stacks in a single array then you will need to divide the SIZE of the initialized array by 2. Then you have to distinguish the two stacks with these basic initialization.如果要在单个数组中实现两个堆栈,则需要将初始化数组的 SIZE 除以 2。然后您必须通过这些基本初始化来区分两个堆栈。

int stack[9], SIZE, max1, max2, top1, top2;
SIZE = 10;
max1 = (SIZE/2) - 1; 
max2 = SIZE - 1;
top1 = -1;
top2 = max1;

so by doing this, they are totally separated.所以通过这样做,他们完全分开了。 so you should have two push methods push1() and push2 and two pop methods pop1() and pop2() separately written in accordance to the respective stack parameters.所以你应该有两个push方法push1()和push2和两个pop方法pop1()和pop2()根据各自的堆栈参数分别编写。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM