Advertisement
Guest User

fREACKING_BRACKETS

a guest
Jan 12th, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.45 KB | None | 0 0
  1. //---------------------------------------------------------------------------
  2. #include <dos.h>
  3. #include <iostream.h>
  4. #include <string.h>
  5. #include <vcl.h>
  6. #pragma hdrstop
  7. #pragma argsused
  8. //---------------------------------------------------------------------------
  9.  
  10. float calcult(std::string& inpt, int x){
  11. unsigned int i = 0;
  12. unsigned int i1 = 0;
  13. unsigned int i2 = 0;
  14. float opr1 = 1;
  15. float opr = 0;
  16. float res = 0;
  17. bool numHasBegun = false, goOut = false, wasMul = false, wasDiv = false, firstTime = true;
  18.  
  19. std::string formtd = "";
  20. std::string inBuf = "";
  21. std::string num = "";
  22. char xToNum[11];
  23.  
  24. i1 = 0;
  25. while(i1 < inpt.length()){
  26. if(inpt[i1] == 'x' || inpt[i1] == 'X'){
  27. itoa(x, xToNum, 10);
  28. inBuf += xToNum;
  29. }
  30. else
  31. inBuf += inpt[i1];
  32. i1++;
  33. }
  34.  
  35. i1 = 0;
  36. while(i1 < inBuf.length()){
  37. while(inBuf[i1] == '+'){
  38. i2++;
  39. i1++;
  40. }
  41. if(i2 && formtd.length() > 0)
  42. i1--;
  43. i2 = 0;
  44. while(inBuf[i1] == '-'){
  45. i2++;
  46. i1++;
  47. }
  48.  
  49. if(i2 % 2)
  50. formtd += "-";
  51. if(!(i2 % 2) && i2 != 0 && inBuf.length() > 0)
  52. formtd += "+";
  53. formtd += inBuf[i1];
  54. i2 = 0;
  55. i1++;
  56. }
  57.  
  58. while(i < formtd.length()){
  59. num = "";
  60. numHasBegun = false;
  61. goOut = false;
  62.  
  63. while((isdigit(formtd[i]) || formtd[i] == '+' || formtd[i] == '-' || formtd[i] == '.' || formtd[i] == 'x') && !goOut){
  64. if(numHasBegun && (formtd[i] == '+' || formtd[i] == '-'))
  65. goOut = true;
  66. num += formtd[i];
  67. numHasBegun = true;
  68. if(!goOut)
  69. i++;
  70. }
  71.  
  72. opr = atof(num.c_str());
  73.  
  74. if(!wasMul && !wasDiv && formtd[i] != '*' && formtd[i] != '/')
  75. res += opr;
  76.  
  77. if(formtd[i] == '*' || wasMul){
  78. opr1 *= opr;
  79. wasMul = true;
  80. if(formtd[i] != '*' && formtd[i] != '/'){
  81. wasMul = false;
  82. res += opr1;
  83. opr1 = 1;
  84. }
  85. if(formtd[i] == '/'){
  86. wasDiv = true;
  87. wasMul = false;
  88. }
  89. }
  90.  
  91. if(formtd[i] == '/' || wasDiv){
  92. if(firstTime){
  93. opr1 = opr;
  94. firstTime = false;
  95. }
  96. else
  97. opr1 = opr1 / opr;
  98. wasDiv = true;
  99.  
  100. if(formtd[i] != '/' && formtd[i] != '*'){
  101. cout << opr1 << endl;
  102. wasDiv = false;
  103. firstTime = true;
  104. res += opr1;
  105. opr1 = 1;
  106. }
  107.  
  108. if(formtd[i] == '*'){
  109. wasDiv = false;
  110. wasMul = true;
  111. }
  112. }
  113. if(!goOut)
  114. i++;
  115. }
  116. return res;
  117. }
  118.  
  119. int main(int argc, char* argv[]){
  120. const min = -10, max = 10;
  121. unsigned int i = 0, brktBorder = 0, brktBorder1 = 0;
  122. int x = 2;
  123. bool mode = false, brkts = true;
  124. int decP, sign;
  125.  
  126. std::string input = "";
  127. std::string buffer = "";
  128. std::string out = "";
  129.  
  130. /*
  131. while(input != "mn" && input != "at"){
  132. cout << "Ruchnoi ili auto rezhim? (mn/at): ";
  133. std::getline(std::cin, input);
  134.  
  135. i = 0;
  136. while(i < input.length()){
  137. while(input[i] == ' ')
  138. input.erase(i, 1);
  139. i++;
  140. }
  141. }
  142.  
  143. if(input == "mn")
  144. mode = true;
  145.  
  146. if(input == "at")
  147. mode = false;
  148. */
  149. cout << "Vvedite formulu funktcii: ";
  150. std::getline(std::cin, input);
  151.  
  152. i = 0;
  153. while(i < input.length()){
  154. while(input[i] == ' ')
  155. input.erase(i, 1);
  156. i++;
  157. }
  158.  
  159. while(brkts){
  160. i = 0;
  161. brkts = false;
  162. brktBorder = 0;
  163. brktBorder1 = 0;
  164. out = "";
  165. while(i < input.length()){
  166. if(input[i] == '('){
  167. brktBorder = i;
  168. brkts = true;
  169. }
  170. i++;
  171. }
  172. i = brktBorder;
  173. buffer = "";
  174. while(input[i] != ')' && i < input.length()){
  175. buffer += input[i];
  176. i++;
  177. }
  178.  
  179. brktBorder1 = i;
  180. if(brktBorder1 >= input.length())
  181. brktBorder1 = input.length() - 1;
  182.  
  183. buffer = fcvt(calcult(buffer, x), 15, &decP, &sign);
  184. buffer.insert(decP, ".");
  185.  
  186. i = 0;
  187. while(i < brktBorder){
  188. out += input[i];
  189. i++;
  190. }
  191.  
  192. out += buffer;
  193.  
  194. i = brktBorder1 + 1;
  195. while(i < input.length() && brktBorder1 < input.length() - 1){
  196. out += input[i];
  197. i++;
  198. }
  199.  
  200. input = out;
  201. }
  202. cout << out << endl;
  203. system("pause");
  204. return 0;
  205. }
  206. //---------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement