Guest User

pesci vi odio

a guest
Jul 28th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.81 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <vector>
  3. #include <stack>
  4. using namespace std;
  5.  
  6. vector <int> direzione, dimensione;
  7.  
  8. int mangia(int N)
  9. {
  10.     stack<int> s;
  11.     for(int i=0; i<N; i++)
  12.     {
  13.         if(direzione[i] == 1)
  14.         {
  15.             while(s.top() > dimensione[i] && !s.empty())
  16.                 s.pop();
  17.             if(s.empty()) s.push(dimensione[i]);
  18.         }
  19.         printf("a ");
  20.     }
  21.     return s.size();
  22. }
  23.  
  24. int main()
  25. {
  26.     FILE *fr, *fw;
  27.     int N, i, a, b;
  28.     fr = fopen("input.txt", "r");
  29.     fw = fopen("output.txt", "w");
  30.     fscanf(fr, "%d\n", &N);
  31.     for(i=0; i<N; i++)
  32.     {
  33.         fscanf(fr, "%d %d\n", &a, &b);
  34.         direzione.push_back(a);
  35.         dimensione.push_back(b);
  36.     }
  37.     fprintf(fw, "%d\n", mangia(N));
  38.     fclose(fr);
  39.     fclose(fw);
  40.     return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment