Josif_tepe

Untitled

Sep 9th, 2025
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.66 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. const int MAX_SIZE = 100;
  4. struct Queue {
  5.     string a[MAX_SIZE];
  6.     int S, E;
  7.    
  8.     void init() {
  9.         S = 0;
  10.         E = -1;
  11.     }
  12.     bool isFull() {
  13.         if(E == MAX_SIZE - 1) {
  14.             return true;
  15.         }
  16.         else {
  17.             return false;
  18.         }
  19.     }
  20.     bool isEmpty() {
  21.         if(E == -1) {
  22.             return true;
  23.         }
  24.         else {
  25.             return false;
  26.         }
  27.     }
  28.     void push(string x) {
  29.         if(isFull()) {
  30.             cout << "queue overflow" << endl;
  31.             exit(-1);
  32.         }
  33.         E++;
  34.         a[E] = x;
  35.     }
  36.     string front() {
  37.         if(isEmpty()) {
  38.             cout << "prazen red" << endl;
  39.             exit(-1);
  40.         }
  41.         return a[S];
  42.     }
  43.     string pop() {
  44.         if(isEmpty()) {
  45.             cout << "prazen red" << endl;
  46.             exit(-1);
  47.         }
  48.        
  49.         string x = a[S];
  50.        
  51.         for(int i = 0; i < E; i++) {
  52.             a[i] = a[i + 1];
  53.         }
  54.         E--;
  55.        
  56.         return x;
  57.     }
  58.     int size() {
  59.         return E + 1;
  60.     }
  61. };
  62.  
  63.  
  64.  int main() {
  65.     Queue red;
  66.      red.init();
  67.      
  68.      int n;
  69.      cin >> n;
  70.      
  71.      for(int i = 0; i < n; i++) {
  72.          string patika;
  73.          cin >> patika;
  74.          
  75.          if(red.isEmpty() == true){
  76.              red.push(patika);
  77.          }
  78.          else {
  79.              if(red.front() != patika) {
  80.                  red.pop();
  81.              }
  82.              else {
  83.                  red.push(patika);
  84.              }
  85.          }
  86.      }
  87.      
  88.      cout << red.size() << endl;
  89.  
  90.        
  91.     return 0;
  92. }
  93.  
Advertisement
Add Comment
Please, Sign In to add comment