def checkorder(arr)
n = arr.length
i = 1
while i < n and arr[ i ] == arr[ 0 ]
i += 1
end
if i < n
if arr[i] > arr[i-1]
flag = 1
for k in i..n-1
if arr[k] < arr[k-1]
flag = 0
end
end
if flag == 1
p "Ascending Order!"
else
p "Unordered!"
end
elsif arr[i] < arr[i-1]
flag = 1
for k in i..n-1
if arr[k] > arr[k-1]
flag = 0
end
end
if flag == 1
p "Descending Order!"
else
p "Unordered!"
end
end
end
end
def main()
arr = [1,2,3,4,5,6,7,8,9,10,2021,2022,2023]
arr2 = [9,8,7,6,5,4,3,2,1]
arr3 = [1,2,3,4,5,-1,-2,-4]
arr4 = [9,8,7,6,5,3,2,10]
matrix = [arr, arr2, arr3, arr4]
for i in 0..3
checkorder(matrix[i])
end
end
main
ZGVmIGNoZWNrb3JkZXIoYXJyKQogICAgbiA9IGFyci5sZW5ndGgKICAgIGkgPSAxCiAgICB3aGlsZSBpIDwgbiBhbmQgYXJyWyBpIF0gPT0gYXJyWyAwIF0KICAgICAgICBpICs9IDEKICAgIGVuZAogICAgaWYgaSA8IG4KICAgICAgICBpZiBhcnJbaV0gPiBhcnJbaS0xXQogICAgICAgICAgICAgICAgIGZsYWcgPSAxCiAgICAgICAgICAgICAgICAgZm9yIGsgaW4gaS4ubi0xCiAgICAgICAgICAgICAgICAgICAgIGlmIGFycltrXSA8IGFycltrLTFdCiAgICAgICAgICAgICAgICAgICAgICAgZmxhZyA9IDAKICAgICAgICAgICAgICAgICAgICAgZW5kCiAgICAgICAgICAgICAgICAgZW5kCiAgICAgICAgICAgICAgICAgaWYgZmxhZyA9PSAxCiAgICAgICAgICAgICAgICAgICAgcCAiQXNjZW5kaW5nIE9yZGVyISIKICAgICAgICAgICAgICAgICBlbHNlCiAgICAgICAgICAgICAgICAgICAgcCAiVW5vcmRlcmVkISIKICAgICAgICAgICAgICAgICBlbmQKICAgICAgICBlbHNpZiBhcnJbaV0gPCBhcnJbaS0xXQogICAgICAgICAgICAgIGZsYWcgPSAxCiAgICAgICAgICAgICAgZm9yIGsgaW4gaS4ubi0xCiAgICAgICAgICAgICAgICAgIGlmIGFycltrXSA+IGFycltrLTFdCiAgICAgICAgICAgICAgICAgICAgZmxhZyA9IDAKICAgICAgICAgICAgICAgICAgZW5kCiAgICAgICAgICAgICAgZW5kCiAgICAgICAgICAgICAgaWYgZmxhZyA9PSAxCiAgICAgICAgICAgICAgICAgcCAiRGVzY2VuZGluZyBPcmRlciEiCiAgICAgICAgICAgICAgZWxzZQogICAgICAgICAgICAgICAgIHAgIlVub3JkZXJlZCEiCiAgICAgICAgICAgICAgZW5kCiAgICAgICAgZW5kCiAgICBlbmQKZW5kCiAKZGVmIG1haW4oKQogICAgYXJyID0gWzEsMiwzLDQsNSw2LDcsOCw5LDEwLDIwMjEsMjAyMiwyMDIzXQogICAgYXJyMiA9IFs5LDgsNyw2LDUsNCwzLDIsMV0KICAgIGFycjMgPSBbMSwyLDMsNCw1LC0xLC0yLC00XQogICAgYXJyNCA9IFs5LDgsNyw2LDUsMywyLDEwXQogICAgbWF0cml4ID0gW2FyciwgYXJyMiwgYXJyMywgYXJyNF0KICAgIGZvciBpIGluIDAuLjMKICAgICAgICBjaGVja29yZGVyKG1hdHJpeFtpXSkKICAgIGVuZAplbmQKbWFpbg==