Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*Description
- Loni the elephant has four flower pots on his window sill. The pots have specific heights and Loni likes it when they are arranged in an ascending order of height. Loni's mother rearranges the pots every day and Loni gets confused. Now he wants to teach his home robot to do the arrangement.
- For the purpose, write a program sort, which sends the robot a message about how the pots are arranged, given the heights of the pots.
- Input
- On the first and only line of the standard input you will receive four integers h1, h2, h3, h4 - the heights of the pots
- Output
- Print one of the following to the standard output:
- Ascending if the pots have strictly increasing heights
- Descending if the pots have strictly decreasing heights
- Mixed if the pots are not sorted by height
- Constraints
- 0 ≤ h1,h2,h3,h4 ≤ 100;
- Sample tests
- Input
- 3 4 5 6
- Output
- Ascending
- Input
- 3 4 4 5
- Output
- Mixed
- Input
- 6 4 3 1
- Output
- Descending
- Input
- 5 4 6 3
- Output
- Mixed
- */
- let number = gets().split(' ')
- let ascending = 0
- let descending = 0
- for(let i = 0; i < number.length; i++){
- if(Number(number[i]) > Number(number[i + 1])){
- descending++
- }
- if(Number(number[i]) < Number(number[i + 1])){
- ascending++
- }
- }
- if(ascending == 3){
- print('Ascending')
- } else if (descending == 3){
- print('Descending')
- } else if(ascending != 3 && descending != 3){
- print('Mixed')
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement