Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- const int MAX_SIZE = 100;
- struct Queue {
- string a[MAX_SIZE];
- int S, E;
- void init() {
- S = 0;
- E = -1;
- }
- bool isFull() {
- if(E == MAX_SIZE - 1) {
- return true;
- }
- else {
- return false;
- }
- }
- bool isEmpty() {
- if(E == -1) {
- return true;
- }
- else {
- return false;
- }
- }
- void push(string x) {
- if(isFull()) {
- cout << "queue overflow" << endl;
- exit(-1);
- }
- E++;
- a[E] = x;
- }
- string front() {
- if(isEmpty()) {
- cout << "prazen red" << endl;
- exit(-1);
- }
- return a[S];
- }
- string pop() {
- if(isEmpty()) {
- cout << "prazen red" << endl;
- exit(-1);
- }
- string x = a[S];
- for(int i = 0; i < E; i++) {
- a[i] = a[i + 1];
- }
- E--;
- return x;
- }
- int size() {
- return E + 1;
- }
- };
- int main() {
- Queue red;
- red.init();
- int n;
- cin >> n;
- for(int i = 0; i < n; i++) {
- string patika;
- cin >> patika;
- if(red.isEmpty() == true){
- red.push(patika);
- }
- else {
- if(red.front() != patika) {
- red.pop();
- }
- else {
- red.push(patika);
- }
- }
- }
- cout << red.size() << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment