Josif_tepe

Untitled

Sep 3rd, 2025
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.75 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. const int MAX_SIZE = 100;
  4. struct magacin {
  5.     int a[MAX_SIZE];
  6.     int at;
  7.    
  8.     void init() {
  9.         at = -1;
  10.     }
  11.    
  12.     bool isEmpty() {
  13.         if(at == -1) {
  14.             return true;
  15.         }
  16.         else {
  17.             return false;
  18.         }
  19.     }
  20.    
  21.     bool isFull() {
  22.         if(at == MAX_SIZE - 1) {
  23.             return true;
  24.         }
  25.         else {
  26.             return false;
  27.         }
  28.     }
  29.    
  30.    
  31.     void push(int x) {
  32.         if(isFull()) {
  33.             cout << "Stack overflow" << endl;
  34.             exit(-1);
  35.         }
  36.         at++;
  37.         a[at] = x;
  38.     }
  39.    
  40.     int peek() {
  41.         if(isEmpty()) {
  42.             cout << "empty stack" << endl;
  43.             exit(-1);
  44.         }
  45.        
  46.         return a[at];
  47.     }
  48.    
  49.     int pop() {
  50.         int front = peek();
  51.        
  52.         at--;
  53.         return front;
  54.     }
  55.    
  56.    
  57.    
  58. };
  59.  
  60. void func(magacin &m)
  61. {
  62.     magacin m2, m3;
  63.    
  64.     m2.init();
  65.     m3.init();
  66.    
  67.     while(m.isEmpty() == false) {
  68.         int p = m.pop();
  69.        
  70.         m2.push(p);
  71.         m3.push(p);
  72.     }
  73.    
  74.     while(m2.isEmpty() == false) {
  75.         int p = m2.pop();
  76.         m.push(p);
  77.     }
  78.    
  79.     while(m.isEmpty() == false) {
  80.         int p1 = m.pop();
  81.         int p2 = m3.pop();
  82.        
  83.         int sum = p1 + p2;
  84.         if(sum > 9) {
  85.             sum = 9;
  86.         }
  87.         cout << sum;
  88.     }
  89.    
  90.     cout << endl;
  91.  
  92.    
  93.    
  94.    
  95. }
  96. int main()
  97. {
  98.     magacin s;
  99.     int no, element, c;
  100.     s.init();
  101.     cout << "Vnesete koj broj da se proveri:";
  102.     cin >> no;
  103.     while(no != 0) {
  104.     element = no%10;
  105.     no /= 10;
  106.         s.push(element);
  107.     }
  108.     func(s);
  109.     return 0;
  110. }
  111.  
Advertisement
Add Comment
Please, Sign In to add comment