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 magacin {
- string a[max_size];
- int at;
- void init() {
- at = -1;
- }
- bool isFull() {
- if(at == max_size - 1) {
- return true;
- }
- return false;
- }
- bool isEmpty() {
- if(at == -1) {
- return true;
- }
- return false;
- }
- void push(string s) {
- if(isFull()) {
- cout << "Full stack size!" << endl;
- return;
- }
- at++;
- a[at] = s;
- }
- string pop() {
- if(isEmpty()) {
- cout << "Stack is empty!" << endl;
- exit(0);
- }
- string s = a[at];
- at--;
- return s;
- }
- string top() {
- if(isEmpty()) {
- cout << "Stack is empty!" << endl;
- exit(0);
- }
- return a[at];
- }
- int size() {
- return at + 1;
- }
- };
- struct red {
- string a[max_size];
- int front, rear;
- void init() {
- front = 0;
- rear = -1;
- }
- bool isEmpty() {
- if(rear == -1) {
- return true;
- }
- return false;
- }
- bool isFull() {
- if(rear == max_size - 1) {
- return true;
- }
- return false;
- }
- void push(string s) {
- if(isFull()) {
- cout << "Queue is full" << endl;
- exit(0); // terminate/exit the program
- }
- rear++;
- a[rear] = s;
- }
- string pop() {
- if(isEmpty()) {
- cout << "Queue is empty!" << endl;
- exit(0);
- }
- string s = a[front];
- for(int i = front; i < rear; i++) {
- a[i] = a[i + 1];
- }
- rear--;
- return s;
- }
- string peek() {
- if(isEmpty()) {
- cout << "Queue is empty! " << endl;
- exit(0);
- }
- return a[front];
- }
- int size() {
- return rear + 1;
- }
- };
- int get_number_of_unpaired_shoes(red Q) {
- magacin st;
- st.init();
- int paired_shoes = 0;
- while(!Q.isEmpty()) {
- string shoe = Q.peek();
- Q.pop();
- if(st.size() > 0 && st.top() != shoe) {
- st.pop();
- paired_shoes++;
- }
- else {
- st.push(shoe);
- }
- }
- cout << "Number of paired shoes: " << paired_shoes << endl;
- cout << "Number of unpaired shoes: " << st.size() << endl;
- return st.size();
- }
- int main()
- {
- int n;
- cout << "Input number of shoes: ";
- cin >> n;
- red Q;
- Q.init();
- for(int i = 0; i < n; i++) {
- string shoe;
- cin >> shoe;
- Q.push(shoe);
- }
- get_number_of_unpaired_shoes(Q);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement