Advertisement
ivangarvanliev

Untitled

Mar 20th, 2025
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.80 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5.     vector<int> heights;
  6.     int height;
  7.  
  8.     while (cin >> height && height != 11111) {
  9.         heights.push_back(height);
  10.     }
  11.  
  12.     int leftPointer = 0;
  13.     while (heights[leftPointer] != 0) {
  14.         leftPointer++;
  15.     }
  16.    
  17.     int rightPointer = heights.size() - 1;
  18.     while (heights[rightPointer] != 0) {
  19.         rightPointer--;
  20.     }
  21.  
  22.     vector<int> visibleTrees;
  23.     for (int i = leftPointer + 1; i < rightPointer; i++) {
  24.         if (heights[i] != 0) {
  25.             visibleTrees.push_back(heights[i]);
  26.         }
  27.     }
  28.     sort(visibleTrees.begin() , visibleTrees.end());
  29.     int maxHeight = visibleTrees.back();
  30.     int minHeight = visibleTrees.front();
  31.  
  32.     cout << maxHeight - minHeight << endl;
  33.  
  34.     return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement