Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- const int MAX_SIZE = 100;
- struct magacin {
- int a[MAX_SIZE];
- int at;
- void init() {
- at = -1;
- }
- bool isEmpty() {
- if(at == -1) {
- return true;
- }
- else {
- return false;
- }
- }
- bool isFull() {
- if(at == MAX_SIZE - 1) {
- return true;
- }
- else {
- return false;
- }
- }
- void push(int x) {
- if(isFull()) {
- cout << "Stack overflow" << endl;
- exit(-1);
- }
- at++;
- a[at] = x;
- }
- int peek() {
- if(isEmpty()) {
- cout << "empty stack" << endl;
- exit(-1);
- }
- return a[at];
- }
- int pop() {
- int front = peek();
- at--;
- return front;
- }
- };
- void func(magacin &m)
- {
- magacin m2, m3;
- m2.init();
- m3.init();
- while(m.isEmpty() == false) {
- int p = m.pop();
- m2.push(p);
- m3.push(p);
- }
- while(m2.isEmpty() == false) {
- int p = m2.pop();
- m.push(p);
- }
- while(m.isEmpty() == false) {
- int p1 = m.pop();
- int p2 = m3.pop();
- int sum = p1 + p2;
- if(sum > 9) {
- sum = 9;
- }
- cout << sum;
- }
- cout << endl;
- }
- int main()
- {
- magacin s;
- int no, element, c;
- s.init();
- cout << "Vnesete koj broj da se proveri:";
- cin >> no;
- while(no != 0) {
- element = no%10;
- no /= 10;
- s.push(element);
- }
- func(s);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment