Advertisement
Guest User

Untitled

a guest
Dec 12th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.56 KB | None | 0 0
  1. class Program
  2. {
  3. static void Main(string[] args)
  4. {
  5. int x;
  6. Console.Write("inserire :");
  7. string op = Console.ReadLine();
  8.  
  9. string ris="";
  10.  
  11. Stack<string> num = new Stack<string>();
  12.  
  13. string[] arr = op.Split(' ');
  14.  
  15. for (int i = 0; i < arr.Length; i++)
  16. {
  17.  
  18. switch (arr[i])
  19. {
  20. case "+":case "-":case "*":case "/":case "^":
  21. {
  22. foreach (var a in num)
  23. {
  24. if (a == "(")
  25. {
  26. int last = ;
  27. }
  28.  
  29. /*if (LaCassssaa.controllo(arr[i]) < LaCassssaa.controllo(a))
  30. {
  31. foreach (var b in num)
  32. {
  33. if (b == "(")
  34. {
  35. string cestino = num.Pop();
  36. break;
  37. }
  38. else
  39. ris += num.Pop();
  40. }
  41. }
  42. }*/
  43. num.Push(arr[i]);
  44. break;
  45. }
  46.  
  47. case "(":
  48. {
  49. num.Push(arr[i]);
  50. break;
  51. }
  52.  
  53. case ")":
  54. {
  55. foreach (var b in num)
  56. {
  57. if (b == "(")
  58. break;
  59. else
  60. ris += b;
  61. }
  62. break;
  63. }
  64.  
  65. case "0":
  66. case "1":
  67. case "2":
  68. case "3":
  69. case "4":
  70. case "5":
  71. case "6":
  72. case "7":
  73. case "8":
  74. case "9":
  75. {
  76. ris += arr[i];
  77. break;
  78. }
  79.  
  80.  
  81.  
  82.  
  83. default:
  84. {
  85. break;
  86. }
  87.  
  88. }
  89.  
  90. }
  91.  
  92. Console.WriteLine(ris);
  93.  
  94. }
  95. }
  96.  
  97. static public int controllo(string a)
  98. {
  99.  
  100. switch (a)
  101. {
  102. case "+":
  103. {
  104. return 1;
  105. }
  106. case "-":
  107. {
  108. return 1;
  109. }
  110. case "*":
  111. {
  112. return 2;
  113. }
  114. case "/":
  115. {
  116. return 2;
  117. }
  118. case "^":
  119. {
  120. return 3;
  121. }
  122. }
  123. return 0;
  124.  
  125.  
  126. }
  127. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement