Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- const int max_size = 1000;
- struct stek {
- string niza[max_size];
- int idx;
- void init() {
- idx = -1;
- }
- bool isEmpty() {
- if(idx == -1) {
- return true;
- }
- else {
- return false;
- }
- }
- bool isFull() {
- if(idx == max_size - 1) {
- return true;
- }
- else {
- return false;
- }
- }
- void push(string x) {
- if(isFull() == true) {
- cout << "nema poveke prostor vo stekot" << endl;
- exit(-1);
- }
- idx++;
- niza[idx] = x;
- }
- string peek() {
- if(isEmpty() == true) {
- cout << "nema element vo stekot" << endl;
- exit(-1);
- }
- return niza[idx];
- }
- string pop() {
- if(isEmpty() == true) {
- cout << "nema element vo stekot" << endl;
- exit(-1);
- }
- string result = niza[idx];
- idx--;
- return result;
- }
- int size() {
- return idx + 1;
- }
- };
- int main()
- {
- int n;
- cin >> n;
- stek s;
- s.init();
- for(int i = 0; i < n; i++) {
- string patika;
- cin >> patika;
- if(s.isEmpty() == true) {
- s.push(patika);
- }
- else {
- if(s.peek() != patika) {
- s.pop();
- }
- else {
- s.push(patika);
- }
- }
- }
- cout << s.size() << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement