JosepRivaille

X09467: Rampes

May 14th, 2015
789
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.02 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5.  
  6. vector<bool> pos_rampas (const vector<int>& v) {
  7.     int n = v.size();
  8.     vector<bool> pos_rampas(n);
  9.     for (int i = 0; i < n-2; ++i) {
  10.         if (v[i] > v[i+1] && v[i+1] > v[i+2]) pos_rampas[i] = true;
  11.         else if (v[i] < v[i+1] && v[i+1] < v[i+2]) pos_rampas[i] = true;
  12.         else pos_rampas[i] = false;
  13.     }
  14.     return pos_rampas;
  15. }
  16.  
  17. int pot_conflictives (const vector<bool>& v) {
  18.     int conflictives = 0;
  19.     int tam_v = v.size();
  20.     for (int i = 0; i < tam_v; ++i) {
  21.         if (v[i] == true && v[i+1] == true) ++conflictives;
  22.         if (v[i] == true && v[i+2] == true) ++conflictives;
  23.     }
  24.     return conflictives;
  25. }
  26.  
  27.  
  28. int main() {
  29.     int n;
  30.     while (cin >> n) {
  31.         vector<int> v(n);
  32.         for (int i = 0; i < n; ++i) cin >> v[i];
  33.         vector<bool> u = pos_rampas(v);
  34.         cout << "posicions amb rampa:";
  35.         for (int i = 0; i < n; ++i) {
  36.             if (u[i] == true) cout << " " << i;
  37.         }
  38.         cout << endl;
  39.         cout << "potencialment conflictives: " << pot_conflictives(u) << endl;
  40.         cout << "---" << endl;
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment