fork download
  1. using System;
  2.  
  3. public class Test
  4. {
  5. public static void Main()
  6. {
  7. string[] input = new string[]{"(","*","(","+","2","3",")","(","-","5","3",")",")"};
  8.  
  9. foreach(string a in input){
  10. Console.Write(a);
  11. }
  12. Console.WriteLine();
  13. stack(input);
  14. }
  15.  
  16. static void stack(string[] data){
  17.  
  18. string[] stk = new string[100];
  19.  
  20. for(int i=0;i<100;i++){
  21. stk[i]=null;
  22. }
  23.  
  24. for(int i=0;i<data.Length;i++){
  25. Console.WriteLine("data["+i+"] : "+data[i]);
  26. if(data[i] ==")" ){
  27. Console.WriteLine("pop start");
  28. stk = pop(stk,data[i]);
  29. }
  30. // else if(data[i] !="*" || data[i] !="/" ||data[i] !="+" ||data[i] !="-"){
  31. // cal(stk,data[i]);
  32. // }
  33. else{
  34.  
  35. stk = push(stk,data[i]);
  36. }
  37. }
  38. Console.WriteLine();
  39. foreach(string b in stk){
  40. Console.Write(b);
  41. }
  42.  
  43. }
  44.  
  45. static string[] push(string[] stk,string d){
  46.  
  47. for(int i=0;i<100;i++){
  48. if(stk[i] == null){
  49. stk[i] = d;
  50. //Console.WriteLine("push : " + stk[i]);
  51. break;
  52. }
  53. }
  54.  
  55.  
  56.  
  57.  
  58. return stk;
  59. }
  60.  
  61. static string[] pop(string[] stk,string d){
  62.  
  63. int sum = 0;
  64. int[] num = new int[10];
  65. string cal = "";
  66.  
  67. for(int i=0;i<10;i++){
  68. num[i]=0;
  69. }
  70.  
  71.  
  72.  
  73. for(int i=99;i>=0;i--){
  74. // Console.WriteLine("stk : " +stk[i]);
  75. if(stk[i] != null){
  76.  
  77. if(stk[i] == "("){
  78. Console.WriteLine("cal go");
  79.  
  80. for(int j = 0;j<10;j++){
  81. if(num[j]!=0){
  82.  
  83. if(cal == "+"){
  84. sum += num[j];
  85. }else if(cal == "-"){
  86. sum -= num[j];
  87. }else if(cal == "*"){
  88. sum *= num[j];
  89. }else{
  90. sum /= num[j];
  91. }
  92.  
  93. }
  94. }
  95. stk[i]=sum;
  96. Console.WriteLine("cal_data : " + sum);
  97. break;
  98. }else if(stk[i] =="*" || stk[i] =="/" || stk[i] =="+" || stk[i] =="-"){
  99. Console.WriteLine("cal save");
  100. cal = stk[i];
  101. stk[i]=null;
  102. }else{
  103. Console.WriteLine("num save");
  104. for(int j = 0;j<10;j++){
  105. if(num[j]==0){
  106. num[j]=Int32.Parse(stk[i]);
  107. stk[i]=null;
  108. Console.WriteLine("pop : " + num[j]);
  109. break;
  110. }
  111. }
  112.  
  113. }
  114.  
  115. }
  116. }
  117. return stk;
  118. }
  119.  
  120.  
  121.  
  122. }
Compilation error #stdin compilation error #stdout 0.02s 131776KB
stdin
Standard input is empty
compilation info
prog.cs(95,13): error CS0029: Cannot implicitly convert type `int' to `string'
Compilation failed: 1 error(s), 0 warnings
stdout
Standard output is empty