Advertisement
coffeebeforecode

naman_bmc

Sep 9th, 2022
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. # If you wish you can import any modules from the standard library
  2. # Do not use modules that are not in the standard library
  3. import sys
  4.  
  5.  
  6. def processArray(array):
  7. '''Modify this function to process `array` as indicated
  8. in the question. At the end, return the appropriate
  9. value.
  10.  
  11. Please create appropriate classes, and use appropriate
  12. data structures as necessary.
  13.  
  14. Do not print anything in this function.
  15.  
  16. Submit this entire program (not just this function)
  17. as your answer
  18. '''
  19. i = 0
  20. k = 0
  21. while i < len(array):
  22. if array[i] >= 100:
  23. array[k] = array[i]
  24. i += 1
  25. k += 1
  26. else:
  27. s = 0
  28. while i < len(array) and array[i] < 100:
  29. s += array[i]
  30. i+=1
  31. array[k] = s
  32. k += 1
  33.  
  34. return k # change this appropriately, if necessary
  35.  
  36. def run():
  37. array = []
  38. for line in sys.stdin:
  39. intval = int(line)
  40. if intval < 0:
  41. break
  42. array.append(intval)
  43. newlen = processArray(array)
  44. for i in range(newlen):
  45. print(array[i])
  46.  
  47. if __name__ == '__main__':
  48. run()
  49.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement