If a list is central symmetry, it is called a central list. for example, 1->3->5->7->9->7->5->3->1 is a central list.
Give you a sequence of numbers, form a link list and then judge whether it is a central list.
输入格式:
A sequence of numbers seperated by comma
输出格式:
If it is a central list output Yes, otherwise No
输入样例:
1,3,5,7,9,7,5,3,1,
输出样例:
Yes
C语言代码
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define maxsize 100
main(){
//input
char string[maxsize];
fgets(string,maxsize,stdin);
int i,j;
int flag=1;
for(i=0,j=strlen(string)-3;i<=j;){
if(string[i]!=string[j]){
flag=0;
break;
}
i+=2;
j-=2;
}
if(flag) printf("Yes");
else printf("No");
}
注意:
1.注意j的初始值,strlen获取的字符串长度包括换行符和结尾的'\0',因此strlen的长度比实际输入大二。
2.之所以采用string获取输入并用strlen判断终止,是因为输入没有明确的终止条件,用getchar()逐个输入很容易导致PTA中运行超时(虽然我也不知道原理是什么)