Advertisement
3vo

Arrangement

3vo
Mar 24th, 2023 (edited)
768
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*Description
  2.  
  3. 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.
  4.  
  5. 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.
  6. Input
  7.  
  8.     On the first and only line of the standard input you will receive four integers h1, h2, h3, h4 - the heights of the pots
  9.  
  10. Output
  11.  
  12. Print one of the following to the standard output:
  13.  
  14.     Ascending if the pots have strictly increasing heights
  15.  
  16.     Descending if the pots have strictly decreasing heights
  17.  
  18.     Mixed if the pots are not sorted by height
  19.  
  20. Constraints
  21.  
  22. 0 ≤ h1,h2,h3,h4 ≤ 100;
  23. Sample tests
  24. Input
  25.  
  26. 3 4 5 6
  27.  
  28. Output
  29.  
  30. Ascending
  31.  
  32. Input
  33.  
  34. 3 4 4 5
  35.  
  36. Output
  37.  
  38. Mixed
  39.  
  40. Input
  41.  
  42. 6 4 3 1
  43.  
  44. Output
  45.  
  46. Descending
  47.  
  48. Input
  49.  
  50. 5 4 6 3
  51.  
  52. Output
  53.  
  54. Mixed
  55. */
  56. let number = gets().split(' ')
  57. let ascending = 0
  58. let descending = 0
  59. for(let i = 0; i < number.length; i++){
  60. if(Number(number[i]) > Number(number[i + 1])){
  61. descending++
  62. }
  63. if(Number(number[i]) < Number(number[i + 1])){
  64. ascending++
  65. }
  66. }
  67. if(ascending == 3){
  68.   print('Ascending')
  69. } else if (descending == 3){
  70.   print('Descending')
  71. } else if(ascending != 3 && descending != 3){
  72.   print('Mixed')
  73. }
  74.  
  75.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement