Advertisement
JosepRivaille

P90620: La Pica d'Estats

Apr 9th, 2015
1,087
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.52 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4.  
  5. //Pre: Llegeix una seqüència d'altures
  6. //Post: La sortida val SI, si hi ha algun pic major que 3143(m)
  7. int main() {
  8.     int p, cim = 0;
  9.     cin >> p;
  10.     int primer, segon;
  11.     segon = p;
  12.     while (p != 0 && cim != 2) {
  13.         primer = p;
  14.         cin >> p;
  15.         segon = p;
  16.         if (cim == 0) {
  17.             if (segon > primer && segon > 3143) ++cim;
  18.         }
  19.         else if (cim == 1) {
  20.             if (primer > segon) ++cim;
  21.             else cim = 0;
  22.         }
  23.     }
  24.     if (p != 0 && cim == 2) cout << "SI" << endl;
  25.     else cout << "NO" << endl;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement