判断输入的字符串是否对称
1 #define _CRT_SECURE_NO_WARNINGS
2 #include<stdio.h>
3 #include<stdlib.h>
4
5 int issymmetry(char *str)// 判读输入的字符串是否对称
6 {
7 int flag = 1; // 假定一开始0为不对称,1为对称
8 char *head = str;// 头指针
9 char *tail = str + strlen(str)-1;//尾指针
10 while (head<tail)
11 {
12 if (*head!=*tail)
13 {
14 flag = 0;
15 break;
16 }
17 head++;
18 tail--;
19 }
20 return flag;
21
22 }
23
24 void main()
25 {
26 char str[1024] = "";
27 printf("请输入一组字符串:\n");
28 scanf("%s",str);
29 int result = issymmetry(str);
30 if (result==0)
31 {
32 printf("你输入的是不对称字符串\n");
33 }
34 else
35 {
36 printf("你输入的是对称字符串\n");
37 }
38 system("pause");
39 }
长风破浪会有时,直挂云帆济沧海
posted on 2015-05-16 09:27 Dragon-wuxl 阅读(288) 评论(0) 收藏 举报
浙公网安备 33010602011771号