Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Text;
- class Enigmanation
- {
- static void Main()
- {
- string input = Console.ReadLine();
- StringBuilder ready = new StringBuilder();
- int counter = 0;
- while (true)
- {
- char ch = input[counter];
- if (char.IsDigit(ch)) ready.Append(ch + " ");
- else if (ch == '+' || ch == '-' || ch == '*' || ch == '%') ready.Append(ch + " ");
- else // if (ch == '(')
- {
- counter++;
- char next = input[counter];
- int result = int.Parse(next.ToString());
- while (true)
- {
- counter++;
- next = input[counter];
- if (next == '+' || next == '-' || next == '*' || next == '%')
- {
- counter++;
- int num = int.Parse(input[counter].ToString());
- switch (next)
- {
- case '+': result += num; break;
- case '-': result -= num; break;
- case '*': result *= num; break;
- case '%': result %= num; break;
- }
- }
- if (next == ')') break;
- }
- ready.Append(result + " ");
- }
- counter++;
- if (input[counter] == '=')
- {
- ready.Append("=");
- break;
- }
- }
- int count = 0;
- for (int i = 0; i < ready.Length; i++)
- {
- if (ready[i] == ' ') count++;
- }
- string s = ready.ToString();
- string[] str = s.Split(' ');
- long output = long.Parse(str[0]);
- for (int i = 1; str[i] != "="; i += 2)
- {
- char op = char.Parse(str[i]);
- long num = long.Parse(str[i + 1]);
- switch (op)
- {
- case '+': output += num; break;
- case '-': output -= num; break;
- case '*': output *= num; break;
- case '%': output %= num; break;
- }
- }
- Console.WriteLine("{0:F3}", output);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement