Advertisement
Josif_tepe

Untitled

Mar 24th, 2025
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. const int MAX = 1000;
  4.  
  5. typedef int info_t;
  6. struct magacin{
  7. info_t M[MAX];
  8. int idx;
  9. void Init(){
  10. idx = -1;
  11. }
  12. void stackUnderFlow(){
  13. cout<<"Emptystack"<<endl;
  14. exit(0);
  15. }
  16. void stackOverFlow(){
  17. cout<<"FullStack"<<endl;
  18. exit(0);
  19. }
  20. bool isEmpty(){
  21. if(idx == -1){
  22. return true;
  23. }else return false;
  24. }
  25. bool isFull(){
  26. if(idx == MAX - 1){
  27. return true;
  28. }else return false;
  29. }
  30. int size(){
  31. return idx + 1;
  32. }
  33. info_t pop(){
  34. if(isEmpty()){
  35. stackUnderFlow();
  36. }
  37. int pom = M[idx];
  38. idx--;
  39. return pom;
  40. }
  41. info_t peek(){
  42. if(isEmpty()){
  43. stackUnderFlow();
  44. }
  45. return M[idx];
  46. }
  47. void push(info_t x){
  48. if(isFull()){
  49. stackOverFlow();
  50. }else{
  51. idx++;
  52. M[idx] = x;
  53. }
  54. }
  55. };
  56.  
  57. void funk(magacin &m){
  58. magacin prevrten,kopija,rezultantna;
  59. prevrten.Init();
  60. rezultantna.Init();
  61. kopija.Init();
  62.  
  63. while(!m.isEmpty()){
  64. int cifra = m.pop();
  65. prevrten.push(cifra);
  66. kopija.push(cifra);
  67. }
  68.  
  69. while(!prevrten.isEmpty()){
  70. m.push(prevrten.pop());
  71. }
  72.  
  73. while(!m.isEmpty()){
  74. int pom = m.pop();
  75. int pos = kopija.pop();
  76. int zbir = pom + pos;
  77. rezultantna.push(zbir > 9 ? 9 : zbir);
  78. }
  79.  
  80. // nema potreba da proveruvame !kopija.isEmpty(), bidejki samo pecatime od rezultantna
  81. // treba da imame samo while(!rezultantna.isEmpty())
  82. while(!rezultantna.isEmpty() and !kopija.isEmpty()){
  83. cout<<rezultantna.pop();
  84. }
  85. }
  86. int main() {
  87.  
  88. magacin s;
  89.  
  90. int no, element, c;
  91. s.Init();
  92.  
  93. cout << "Vnesete koj broj da se proveri:";
  94. cin >> no;
  95. while(no != 0){
  96. element = no%10;
  97. no /= 10;
  98. s.push(element);
  99. }
  100. funk(s);
  101. return 0;
  102.  
  103. }
  104.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement