[Mảng 1 Chiều Cơ Bản]. Bài 17. Mảng đối xứng

View as PDF

Submit solution

Points: 1.00 (partial)
Time limit: 1.0s
Memory limit: 256M
Input: stdin
Output: stdout

Problem source:
28Tech
Problem type
Allowed languages
C, C#, C++, Java, Kotlin, Pascal, PyPy, Python, Scratch

Cho mảng số nguyên A[] gồm N phần tử, kiểm tra xem mảng có đối xứng hay không?


Đầu vào

Dòng đầu tiên là số nguyên dương N

Dòng thứ 2 gồm N số nguyên viết cách nhau một vài khoảng trắng


Giới hạn

1<=N<=10^6

0<=A[i]<=10^6


Đầu ra

In ra YES hoặc NO tương ứng với mảng đối xứng hoặc không.


Ví dụ :

Input 01
5
1 2 3 2 1
Output 01
YES

Comments

Please read the guidelines before commenting.



  • 0
    kietne  commented on Dec. 13, 2025, 2:15 a.m.

    HAI CON TRỎ LÀ KHOẺ NHÉ AE

    include <bits/stdc++.h>

    using namespace std; using ll = long long;

    int main() { ios::syncwithstdio(false); cin.tie(nullptr); // viết code ở đây int n ; cin >> n; int a[n]; for (auto &i : a) cin >> i; int i=0,j=n-1; bool done=false; while(i<=j){ if(a[i]!=a[j]) done=true; i++; j--; } if(done) cout << "NO"; else{ cout << "YES"; } return 0; }


  • 0
    naipret  commented on Sept. 18, 2025, 7:28 a.m.
    #include <iostream>
    #include <vector>
    
    using namespace std;
    
    int main() {
      ios::sync_with_stdio(false);
      cin.tie(nullptr);
    
      int num;
      cin >> num;
    
      vector<int> vec(num);
      for (int &ele : vec) {
        cin >> ele;
      }
    
      for (int idx = 0; idx <= num / 2; idx++) {
        if (vec[idx] != vec[num - 1 - idx]) {
          cout << "NO";
          return 0;
        }
      }
      cout << "YES";
    }
    

  • 0
    id_07  commented on Sept. 6, 2025, 3:03 a.m.
    #include <bits/stdc++.h>
    using namespace std;
    int main() {
        int n;cin>>n;
        int a[n];
        for(int i=0;i&lt;n;i++) cin>>a[i];
    bool f=true;
    for(int i=0;i&lt;n/2;i++) {
        if(a[i]!=a[n-i-1]) f=false;
    }
    if(!f) cout << "NO";
    else cout <<"YES";
    }
    

  • 0
    hngoc  commented on July 4, 2025, 2:26 p.m.
    import math
    n=input()
    a=input().split()
    b=a.copy()
    b.reverse()
    print('YES' if a==b else 'NO')
    

  • 0
    bengokyeuanh99  commented on May 30, 2025, 6:59 p.m.

    include <cstdio>

    constexpr int MAXN = 1000000; int arr[MAXN];

    int main() { int n; if (scanf("%d", &n) != 1) return 1;

    for (int i = 0; i < n; ++i)
        if (scanf("%d", &arr[i]) != 1) return 1;
    
    for (int i = 0; i < n / 2; ++i)
        if (arr[i] != arr[n - 1 - i]) {
            puts("NO");
            return 0;
        }
    
    puts("YES");
    return 0;
    

    }


  • 4
    VDev  commented on Jan. 18, 2025, 1:08 p.m.

    FULL AC

    #include <bits/stdc++.h>
    #include <iomanip>
    #include <cmath>
    #include <climits>
    #define ll long long
    using namespace std;
    ll a[10000011];
    ll cnt = 0, s = 0;
    
    int main(){
        ll n;
        cin >> n;
        bool check = true;
        for(ll i = 0; i < n; i++){
            cin >> a[i];
        }
        for(ll i = 0; i < n / 2; i++){
                if(a[i] != a[n - i - 1]){
                    check = false;
                    break;
                }
        }
        if(check){
                cout << "YES";
        }else{
             cout << "NO";
        }
        return 0;
    }
    

  • -1
    tandatha140904  commented on Dec. 25, 2024, 4:50 p.m.

    include <bits/stdc++.h>

    using namespace std; int doixung(int a[], int n) { int mid = n / 2, i = 1, j = n; while (i <= mid && j > mid) { if (a[i] == a[j]) { i++; j--; } else return 0; } return 1; } int main() { int n; cin >> n; int a[n]; for (int i = 1; i <= n; i++) { cin >> a[i]; } if (doixung(a, n)) { cout << "YES"; } else cout << "NO"; return 0; }


  • -1
    dangsp07  commented on Dec. 12, 2024, 11:41 a.m.

    include <iostream>

    include <vector>

    using namespace std;

    int main() { int n; cin >> n; vector<int> a(n); for (int &x : a) cin >> x; for (int i = 0; i < n / 2; i++) { if (a[i] != a[n - i - 1]) { cout << "NO\n"; return 0; } }

    cout << "YES\n";
    return 0;
    

    }


  • 0
    janekdao  commented on Nov. 30, 2024, 8:27 a.m.

    hay


  • -2
    ichingu  commented on Nov. 8, 2024, 12:50 p.m.


  • -5
    Nakbosstv  commented on Sept. 16, 2024, 3:00 p.m.

    This comment is hidden due to too much negative feedback. Show it anyway.


  • -7
    NTH11112222  commented on June 12, 2024, 2:55 p.m.

    This comment is hidden due to too much negative feedback. Show it anyway.


  • -8
    Itachi  commented on May 4, 2024, 3:10 p.m.

    This comment is hidden due to too much negative feedback. Show it anyway.


  • -17
    2vhoc7  commented on April 1, 2024, 4:17 p.m.

    This comment is hidden due to too much negative feedback. Show it anyway.