Submit solution
Points:
1.00 (partial)
Time limit:
1.0s
Memory limit:
256M
Input:
stdin
Output:
stdout
Problem source:
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
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; }
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; } }
}
hay
This comment is hidden due to too much negative feedback. Show it anyway.
This comment is hidden due to too much negative feedback. Show it anyway.
This comment is hidden due to too much negative feedback. Show it anyway.
This comment is hidden due to too much negative feedback. Show it anyway.