Advertisement
Guest User

Untitled

a guest
Dec 6th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.64 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <ctype.h>
  4.  
  5. #define size 10
  6.  
  7. double tab[size];
  8. int elem=0;
  9.  
  10. void push(double liczba)
  11. {
  12. if (elem>=size-1)
  13. printf("przekroczono rozmiar stosu");
  14. else
  15. {
  16. printf("dodano element %f na indeksie %d\n",liczba,elem);
  17. tab[elem]=liczba;
  18. ++elem;
  19. }
  20. }
  21.  
  22. double pop()
  23. {
  24. if (elem>0)
  25. {
  26. elem--;
  27. double element=tab[elem];
  28. tab[elem]=0;
  29. printf("usunieto %f\n",element);
  30. return element;
  31. }
  32. }
  33.  
  34. int main()
  35. {
  36. while(1)
  37. {
  38. char ch[35];
  39. scanf("%s",ch);
  40. int i=0;
  41. for(;i<sizeof(ch);++i)
  42. {
  43. if (ch[i]==' ')
  44. continue;
  45.  
  46. else if (ch[i]=='q')
  47. break;
  48.  
  49. else if(isdigit(ch[i]))
  50. {
  51. char c[10];
  52. int xd=i;
  53. int h=0;
  54. if (isdigit(ch[i+1]))
  55. {
  56. while(isdigit(ch[xd]))
  57. {
  58. c[h]=ch[xd];
  59. ++xd;
  60. ++h;
  61. }
  62. double number=strtol(c, NULL, 10);
  63. push(number);
  64. }
  65. else
  66. {
  67. double number=ch[i]-'0';
  68. push(number);
  69. }
  70.  
  71. i+=h;
  72. }
  73.  
  74. else if (ch[i]=='+')
  75. {
  76. if (elem)
  77. {
  78. double x=pop();
  79. double y=pop();
  80. double w=x+y;
  81. push(w);
  82. }
  83. else
  84. printf("stos pusty\n");
  85. }
  86.  
  87. else if (ch[i]=='-')
  88. {
  89. if (elem)
  90. {
  91. double x=pop();
  92. double y=pop();
  93. double w=y-x;
  94. push(w);
  95. }
  96. else
  97. printf("stos pusty\n");
  98. }
  99.  
  100. else if (ch[i]=='=')
  101. {
  102. if (elem)
  103. pop();
  104. else
  105. printf("stos pusty\n");
  106. }
  107.  
  108. else if (ch[i]=='*')
  109. {
  110. if (elem)
  111. {
  112. double x=pop();
  113. double y=pop();
  114. double w=y*x;
  115. push(w);
  116. }
  117. else
  118. printf("stos pusty\n");
  119. }
  120.  
  121. else if (ch[i]=='/')
  122. {
  123. if (elem)
  124. {
  125. double x=pop();
  126. double y=pop();
  127. double w=y/x;
  128. push(w);
  129. }
  130. else
  131. printf("stos pusty\n");
  132. }
  133. }
  134. }
  135. }
  136.  
  137.  
  138. #include <stdio.h>
  139. #include <stdlib.h>
  140. int main()
  141. {
  142. struct RZYM
  143. {
  144. int arab;
  145. char *rzym;
  146. } rz[]={{1,"I"},{4,"IV"},{5,"V"},{9,"IX"},{10,"X"},{40,"XL"},{50,"L"},{90,"XC"},{100,"C"},{400,"CD"},{500,"D"},{900,"CM"},{1000,"M"}};
  147. int liczba;
  148. scanf("%d",&liczba);
  149. int ktoryelem=12;
  150. int elem=rz[ktoryelem].arab;
  151. while (liczba>0)
  152. {
  153. if (liczba>=elem)
  154. {
  155. while(liczba>=elem)
  156. {
  157. printf("%s",rz[ktoryelem].rzym);
  158. liczba-=elem;
  159. }
  160. elem=rz[--ktoryelem].arab;
  161. }
  162. else
  163. elem=rz[--ktoryelem].arab;
  164. }
  165. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement