Advertisement
dxvmxnd

Untitled

Mar 13th, 2024
16
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. bool isReverseSubsequence(int* sequence, int startIndex, int endIndex, int size) {
  2. bool isCorrect;
  3. int i, j;
  4.  
  5. i = startIndex;
  6. j = endIndex;
  7. while (i < j) {
  8. if (sequence[i] != sequence[j]) {
  9. isCorrect = false;
  10. exit;
  11. }
  12. i++;
  13. j--;
  14. }
  15. isCorrect = true;
  16.  
  17. return isCorrect;
  18. }
  19.  
  20. void findReversing(int* arr, int size, int& startIndex, int& endIndex) {
  21. int maxI, maxJ;
  22.  
  23. maxI = startIndex;
  24. maxJ = startIndex;
  25.  
  26. for (int i = startIndex; i <= endIndex; i++) {
  27. for (int j = i; j <= endIndex; j++) {
  28. if (isReverseSubsequence(arr, i, j, size)) {
  29. if ((j - i) > (maxJ - maxI)) {
  30. cout << "im = " << i << endl;
  31. cout << "jm = " << j << endl;
  32. maxI = i;
  33. maxJ = j;
  34. }
  35. }
  36. }
  37. }
  38.  
  39. startIndex = maxI;
  40. endIndex = maxJ;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement