码迷,mamicode.com
首页 > 其他好文 > 详细

判断一个字符串是否为回文数字符串

时间:2015-04-26 19:48:54      阅读:351      评论:0      收藏:0      [点我收藏+]

标签:回文数字符串

#include<stdio.h>
#define STRLEN 100

int Is_palindromic_str(char *str)
{
	int left = 0;//字符串数组的第一个字母的下标
	int i = 0;
	while(str[i] != '\0')
	{
		i++;
	}
	int right = i - 1;//字符串数组最后一个字母(非‘\0’)的下标
	while(left <= right)
	{
		if(str[left] == str[right])//判断左右字符是否一致,一致的话判断下一个
		{
			left++;
			right--;
		}
		else 
			return -1;//不一致,表明不是回文数字符串
	}
	return 1;
}

int main()
{
	char str[STRLEN];
	int i = 1; //循环控制的条件
	while(i)
	{
		printf("Please input the str you want to judge:\n");
		scanf("%s",str);

		if(Is_palindromic_str(str) != -1)
		{
			printf("It's a palidromic string!\n");
		}
		else
		{
			printf("It's not a palidromic string!\n");
		}
		printf("continue:1,break:0\n");
		scanf("%d",&i);
	}
	return 0;
}

技术分享

判断一个字符串是否为回文数字符串

标签:回文数字符串

原文地址:http://blog.csdn.net/zongyinhu/article/details/45291095

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!