Aaron学习笔记

少壮不努力,长大没饭吃!
posts - 4, comments - 13, trackbacks - 0, articles - 37

带空格的回文判断

Posted on 2009-03-26 12:35 赞劲小子 阅读(493) 评论(0)  编辑 收藏 引用 所属分类: 日常练习
带空格的回文判断,C++大学教程上的
#include "stdlib.h"
#include 
"stdio.h"
/*
**判断回文,忽略空格
*/

bool huiwen(char *string); 
int main(){
    
char name[20];
    
char *string = name;
    
while(*string != EOF){
        printf(
"please enter a string: ");
        gets(
string);
        
if(huiwen(string== true)
            printf(
"%s is a huiwen\n",string);
        
else
            printf(
"%s is not a huiwen\n",string);
    }

    
return 0;
}


bool huiwen(char *string){
    
/*
    ** 申明一个寄存器字符串temp用来指向string的最后一个字符
    ** 记住:要temp--,否则temp指向'\0'
    
*/

    register 
char * temp = string;
    
while(*temp != '\0')
        temp
++;
    temp
--;
    
/*
    ** 判断是否是回文
    
*/

    
while(string < temp)
    
{
        
while(*string == ' ')
            
string++;
        
while(*temp == ' ')
            temp
--;
        
if(*string != *temp)
            
return false;
        
else{
            
string++;
            temp
--;
        }

    }

    
return true;
}

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理