[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
    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; }


  • 0
    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


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


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

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


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

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


  • -9
    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.