csansoon

P7.10 X09467 Ramps

Nov 14th, 2018
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.05 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. vector<bool> ramps_pos(const vector <int>& V) {
  6.     vector<bool> ramps(V.size());
  7.     for(int i = 0; i < V.size() - 2; ++i) {
  8.         if((V[i] < V[i+1] and V[i+1] < V[i+2])
  9.            or (V[i] > V[i+1] and V[i+1] > V[i+2])) ramps[i] = true;
  10.     }
  11.     return ramps;
  12. }
  13.  
  14. int pot_conflictive(const vector <bool>& B) {
  15.     int count = 0;
  16.     for(int j = 0; j < B.size() - 2; ++j) {
  17.         if(B[j] and B[j+1]) ++count;
  18.         if(B[j] and B[j+2]) ++count;
  19.     }
  20.     return count;
  21. }
  22.  
  23. int main() {
  24.     int n;
  25.     while (cin >> n) {
  26.         vector<int> V(n);
  27.         for(int i = 0; i < n; ++i) cin >> V[i];
  28.         vector<bool> ramps(n);
  29.         ramps = ramps_pos(V);
  30.         int m = pot_conflictive(ramps);
  31.         cout << "positions with a ramp:";
  32.         for(int j = 0; j < n; ++j)
  33.             if(ramps[j]) cout << " " << j;
  34.         cout << endl << "potentially conflictive: " << m << endl << "---" << endl;
  35.     }
  36. }
  37.  
  38. // (c) Carlos Sansón (Best pro1 delegate ever for sure) @csansoon
Advertisement
Add Comment
Please, Sign In to add comment