当前位置:网站首页>Are the numbers entered symmetrical?

Are the numbers entered symmetrical?

2022-08-10 01:47:00 -JMY-

Title description

Enter an integer N from the keyboard (4<=N<=20), then input N numbers to determine whether the input numbers are symmetrical, which is the output

"YES", otherwise output "NO"?(Note that N can be odd or even).Symmetric means that the numbers are read forward and backward

It all reads the same.

For example, there are 4 numbers: 1 2 2 1,It is symmetrical. For example, there are 5 numbers: 1 2 3 2 1. It is also symmetrical, but there are 5 numbers: 1 2 3

1 2, it is not symmetrical.

Enter

Line 1 has an integer n (4<=n<=20)

Line 2 has n integers.

Output

If it is symmetrical, please output: YES, otherwise output: NO.

Sample input

4

1 2 2 1

Sample output

YES

Reference code:

#include
using namespace std;
int n,a[15],t[25],maxn,k;
int main(){
scanf("%d",&n);
for(int i=0;i scanf("%d",a+i);
for(int i=0;i if(a[i]!=a[n-1-i]){
printf("NO");
return 0;
}
printf("YES");
return 0;
}

原网站

版权声明
本文为[-JMY-]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/222/202208092346036874.html