Advertisement
nicuvlad76

Untitled

Jan 15th, 2021
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define N 1001
  3. using namespace std;
  4. ifstream fin("secvpal.in");
  5. ofstream fout("secvpal.out");
  6. int n, v[N];
  7. bool palindrom(int i,int j)
  8. {
  9. while(i<j)
  10. {
  11. if(v[i]!=v[j])return 0;///daca nu e palin
  12. i++; j--;
  13. }
  14. return 1;
  15. }
  16. int main()
  17. {
  18. int i,j,lc,lmax=0,st,dr;
  19. fin>>n;
  20. for(i=1;i<=n;i++)fin>>v[i];
  21. ///alg
  22. for(i=1;i<=n;i++)
  23. {
  24. lc=0;
  25. for(j=n;j>i;j--)
  26. if(v[i]==v[j] && palindrom(i,j))///capetele egale
  27. {
  28. lc=j-i; break;
  29. }
  30. if(lc>lmax){lmax=lc;st=i;dr=j;}
  31. }
  32. fout<<st<<' '<<dr;
  33. return 0;
  34. }
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement