Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- const int N = 1e3 + 10;
- int n, a[N];
- bool check(int l, int r) {
- while (l < r) {
- if (a[l] != a[r]) return 0;
- l ++;
- r --;
- }
- return 1;
- }
- int main () {
- cin >> n;
- for (int i = 1; i <= n; i ++) {
- cin >> a[i];
- }
- int len = 0; //记录已经出现过的最长回文数组长度
- int l, r;
- for (int i = 1; i <= n; i ++) {
- for (int j = i; j <= n; j ++) {
- // 判断 (i,j)是否是回文数组
- if (j - i + 1 <= len) continue;
- if (check(i, j)) {
- len = j - i + 1;
- l = i;
- r = j;
- }
- }
- }
- for (int i = l; i <= r; i ++) {
- cout << a[i] << ' ';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement