ulvis.paste.net

Paste Search Dynamic
Recent pastes
maximal minimal
  1. #!/bin/bash
  2. read b
  3. read -a arr
  4. maximal=${arr[0]}
  5. minimal=${arr[0]}
  6. mini=0
  7. maxi=0
  8. for (( i=1;i<b;i++ ))
  9. do
  10. if [ $maximal -lt ${arr[i]} ] ; then
  11. maximal=${arr[i]}
  12. maxi=$i
  13. fi
  14. if [ $minimal -gt ${arr[i]} ] ; then
  15. minimal=${arr[i]}
  16. mini=$i
  17. fi
  18. done
  19. if [ $maxi -lt $mini ] ; then
  20. tmp=$maxi
  21. maxi=$mini
  22. mini=$tmp
  23. fi
  24. if [ $mini -lt $maxi ]
  25. then
  26. for ((i=0;i<=mini;i++))
  27. do
  28. echo ${arr[$i]}
  29. done
  30. for ((i=maxi-1;i>mini;i--))
  31. do
  32. echo ${arr[$i]}
  33. done
  34. for ((i=maxi;i<=b;i++))
  35. do
  36. printf "%s" ${arr[$i]}
  37. done
  38. fi
Parsed in 0.007 seconds