Demo entry 6683943

1

   

Submitted by anonymous on Dec 14, 2017 at 04:21
Language: C. Code size: 792 Bytes.

bool palindrome(char *s)   //定义返回值为布尔类型的函数  
    {  
        char *a = s;<span style="white-space:pre;">     </span>//新定义一个指针  
        int i = 0,j=0,k=0;  
        while (*a != '\0')     <span style="white-space:pre;">  </span>//使这个指针遍历到最后一位  
        {  
            a++;  
            i++;  
        }  
        a--;                     //因为最后一为为'\0'所以减一位  
        while (*s != '\0')       //进行两个比较  
        {  
            if (*s == *a)  
            {  
                   
                k++;  
            }  
            else   
            {  
                return false;  
            }  
            s++;  
            a--;  
        }  
        if (k == i)           //如果每个都相等 k=i返回true  
        {  
            return true;  
        }  
    }  

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).