JosepRivaille

X67194: Seqüències quasi-creixents (2)

Apr 9th, 2015
341
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.00 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4.  
  5. void info_sequencia(int n, bool& es_qc, int& p_qc) {
  6.     if (n <= 2) {
  7.         for (int i = n; i != 0; --i) cin >> n;
  8.         cout << p_qc << endl;
  9.     }
  10.     else {
  11.         int primer, segon = 0, tercer = 0;
  12.         int aux = n - 3;
  13.         for (int i = 3; i != 0; --i) {
  14.             primer = segon;
  15.             segon = tercer;
  16.             cin >> n;
  17.             tercer = n;
  18.         }
  19.         if (primer >= segon && primer >= tercer) es_qc = false;
  20.         if (es_qc) ++p_qc;
  21.         while (aux != 0) {
  22.             primer = segon;
  23.             segon = tercer;
  24.             cin >> n;
  25.             tercer = n;
  26.             if (primer >= segon && primer >= tercer) es_qc = false;
  27.             if (es_qc) ++p_qc;
  28.             --aux;
  29.         }
  30.         cout << p_qc << endl;
  31.     }
  32. }
  33.  
  34. //Pre: Llegeix diverses seqüències de naturals
  35. //Post: Escriu la posició de quasi-creixement i el total de seq. quasi creixents
  36. int main() {
  37.     int n;
  38.     int count = 0;
  39.     while (cin >> n && n != 0) {
  40.         bool es_qc = true;
  41.         int p_qc = 2;
  42.         info_sequencia(n, es_qc, p_qc);
  43.         if (es_qc) ++count;
  44.     }
  45.     cout << "Quasi-creixents: " << count << endl;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment