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 {
- int idx;
- int niza[max_size];
- 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;
- }
- }
- int size() {
- return idx + 1;
- }
- void push(int element) {
- if(isFull()) {
- cout << "Nema poveke mesto za elementi" << endl;
- return;
- }
- idx++;
- niza[idx] = element;
- }
- void pop() {
- if(isEmpty()) {
- cout << "Stekot e prazen" << endl;
- return;
- }
- idx--;
- }
- int top() {
- if(isEmpty()) {
- cout << "Nema elementi vo stekot" << endl;
- return -1;
- }
- return niza[idx];
- }
- };
- void func(magacin &m)
- {
- magacin s1;
- s1.init();
- magacin s2;
- s2.init();
- while(!m.isEmpty()) {
- s1.push(m.top());
- s2.push(m.top());
- m.pop();
- }
- cout << endl;
- while(!s1.isEmpty()) {
- m.push(s1.top());
- s1.pop();
- }
- while(!m.isEmpty()) {
- int cifra = m.top() + s2.top();
- if(cifra > 9) {
- cifra = 9;
- }
- s1.push(cifra);
- m.pop();
- s2.pop();
- }
- while(!s1.isEmpty()) {
- m.push(s1.top());
- s1.pop();
- }
- }
- 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);
- while(!s.isEmpty()) {
- cout << s.top();
- s.pop();
- }
- cout << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement