zoukankan      html  css  js  c++  java
  • 判断字符是否为回文

    Code
    #include <iostream.h>
    #include 
    <stdio.h>
    #include 
    <assert.h>
    bool IsSymmetry(const char* p)
        {
            assert(p
    !=NULL);//判断指针是否为空
            const char* q=p;//指向常字符的指针    
            int len=0;
            
    while(*q++!='\0')
            {
                len
    ++;
            }        
            
    bool bSign=true;
            q
    =p+len-1;
            
    if (0<len)
            {
                
    for (int i=0;i<len/2;i++)
                {
                    
    if(*p++!=*q--){ bSign=false;break;};
                }
            }
            
    if(bSign==true)
            {
                printf(
    "Yes!\n");
            }
            
    else
            {
                printf(
    "No!\n");
            }
            
    return bSign;
        }



    void main()
    {
        
    char *str="abcdeffedcba";
        
        cout
    <<IsSymmetry(str)<<endl;
    }
  • 相关阅读:
    pat 09-排序1. 排序(25)
    pat 06-图2. Saving James Bond
    hdu 2818 Building Block
    并查集
    hdu 1213 How Many Tables
    hdu 1232 畅通工程
    hdu 1258 Sum It Up
    如何查看Navicat 查询结果
    Navicat查询功能怎么用
    如何设置Navicat 筛选向导
  • 原文地址:https://www.cnblogs.com/jinweida/p/1455051.html
Copyright © 2011-2022 走看看