fork download
  1. def checkorder(arr)
  2. n = arr.length
  3. i = 1
  4. while i < n and arr[ i ] == arr[ 0 ]
  5. i += 1
  6. end
  7. if i < n
  8. if arr[i] > arr[i-1]
  9. flag = 1
  10. for k in i..n-1
  11. if arr[k] < arr[k-1]
  12. flag = 0
  13. end
  14. end
  15. if flag == 1
  16. p "Ascending Order!"
  17. else
  18. p "Unordered!"
  19. end
  20. elsif arr[i] < arr[i-1]
  21. flag = 1
  22. for k in i..n-1
  23. if arr[k] > arr[k-1]
  24. flag = 0
  25. end
  26. end
  27. if flag == 1
  28. p "Descending Order!"
  29. else
  30. p "Unordered!"
  31. end
  32. end
  33. end
  34. end
  35.  
  36. def main()
  37. arr = [1,2,3,4,5,6,7,8,9,10,2021,2022,2023]
  38. arr2 = [9,8,7,6,5,4,3,2,1]
  39. arr3 = [1,2,3,4,5,-1,-2,-4]
  40. arr4 = [9,8,7,6,5,3,2,10]
  41. matrix = [arr, arr2, arr3, arr4]
  42. for i in 0..3
  43. checkorder(matrix[i])
  44. end
  45. end
  46. main
  47.  
Success #stdin #stdout 0.01s 6588KB
stdin
Standard input is empty
stdout
"Ascending Order!"
"Descending Order!"
"Unordered!"
"Unordered!"