Advertisement
pypcdev

Untitled

Apr 16th, 2021
736
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.79 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. typedef long double ld;
  5. #define int ll
  6. #define fi first
  7. #define se second
  8. #define pb push_back
  9. #define pf push_front
  10. #define ppb pop_back
  11. #define ppf pop_front
  12. #define INF (ll)1e18
  13.  
  14. const int NMAX=1e2;
  15. int a[NMAX+500];
  16.  
  17. signed main(){
  18.     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  19.     int n;
  20.     cin>>n;
  21.     for(int i=1;i<=n;i++)cin>>a[i];
  22.     for(int i=n;i>=1;i--){
  23.         //суфікс-паліндром довжини i
  24.         bool ok=1;
  25.         for(int ii=n-i+1;ii<=n;ii++)if(a[ii]!=a[n-(ii-(n-i+1))])ok=0;
  26.         if(ok){
  27.             cout<<n-i<<"\n";
  28.             for(int ii=(n-i);ii>=1;ii--){
  29.                 cout<<a[ii]<<" ";
  30.             }cout<<"\n";
  31.             return 0;
  32.         }
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement