1 条题解

  • 0
    @ 2023-6-11 12:21:11

    C++ :

    #include<bits/stdc++.h>
    using namespace std;
    
    
    int main() {
    	int n,a[20],p;
    	cin>>n;
    	int i;
    	for(i = 0; i < n; i++) {
    		cin>>a[i];
    	}
    	for(i = 0;i < n / 2;i++){
    		if(a[i] != a[n - i - 1]){
    			cout<<"NO";
    			return 0;
    		}
    	}
    	
    	cout<<"YES";
    }
    
    

    Java :

    
    import java.util.Scanner;
    public class Main {
        public static void main(String[] args) {
            Scanner scanner = new Scanner(System.in);
            int num1 = scanner.nextInt();
    //        int num2 = scanner.nextInt();
            int[] a = new int[num1];
            int count1 = 0,count2 = 0, count3 = 0;
            for (int i = 0; i < num1; i++) {
                a[i] = scanner.nextInt();
            }
            for (int i = 0 ,j = num1 - 1; i < num1 && j >= 0; i++,j--) {
                if(a[i] != a[j]){
                    System.out.println("NO");
                    break;
                }
                if(i == num1 - 1) System.out.println("YES");
            }
    
    
        }
    
        public static boolean judge(int i,int j){
            int a,s = 0;
            while(i != 0){
                a = i % 10;
                s = s + a;
                i /= 10;
            }
            if(s == j)return true;
            else return false;
        }
    
        public static void paiXu(int[] a){
            int temp;
            for(int i = 0;i < a.length - 1;i++){
                for(int k = 0;k < a.length - i - 1;k++){
                    if(a[k] > a[k + 1]){
                        temp = a[k];
                        a[k] = a[k + 1];
                        a[k + 1] = temp;
                    }
                }
            }
        }
    }
    
    

    Python :

    import sys
    n=int(input())
    s1=list(map(int,input().split()))
    s2=s1[::-1]
    for i in range(len(s1)):
        if s1[i]!=s2[i]:
            print("NO")
            sys.exit()
    print("YES")
            
    
    
    • 1

    【入门】输入的这些数是否对称

    信息

    ID
    2688
    时间
    1000ms
    内存
    16MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者