簡體   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;
}

檢查這段代碼我沒有得到正確的 output 這里的字符串應該是 a's 和 b's 和 X 應該在字符串的中間,我們必須檢查字符串是否是回文。

如果要在單個數組中實現兩個堆棧,則需要將初始化數組的 SIZE 除以 2。然后您必須通過這些基本初始化來區分兩個堆棧。

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

所以通過這樣做,他們完全分開了。 所以你應該有兩個push方法push1()和push2和兩個pop方法pop1()和pop2()根據各自的堆棧參數分別編寫。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM