mstoyanov7

pipes

Apr 26th, 2021
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. #include <iostream>
  2. #include <array>
  3. #include <vector>
  4.  
  5. const int maxSize = 1000;
  6.  
  7. std::array<int, maxSize> readInput(int& numberOfPipes) {
  8. std::array<int, maxSize> arr{};
  9.  
  10. for (int i = 0; i < numberOfPipes; ++i) {
  11. std::cin >> arr[i];
  12. }
  13. return arr;
  14. }
  15.  
  16. void checkLifeTime(std::array<int, maxSize>& checkUp, std::array<int, maxSize>& installation, int& numberOfPipes) {
  17. int lifetime = 0;
  18.  
  19. for (int i = 0; i < numberOfPipes; ++i) {
  20. int damage = installation[i] - checkUp[i];
  21.  
  22. while (installation[i] > 0) {
  23. if (damage > installation[i]) {
  24. break;
  25. }
  26. installation[i] -= damage;
  27. lifetime++;
  28. }
  29. std::cout << lifetime << ' ';
  30. lifetime = 0;
  31. }
  32.  
  33. }
  34.  
  35. int main() {
  36. int numberOfPipes;
  37. std::cin >> numberOfPipes;
  38.  
  39. std::array<int, maxSize> checkUp = readInput(numberOfPipes);
  40. std::array<int, maxSize> installation = readInput(numberOfPipes);
  41. checkLifeTime(checkUp, installation, numberOfPipes);
  42. }
Advertisement
Add Comment
Please, Sign In to add comment