Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Text.RegularExpressions;
- class UserLogs
- {
- static void Main()
- {
- string input = Console.ReadLine();
- List<string> nums = input.Split(new string[] { " ", "-", "+", "*", "/" }, StringSplitOptions.RemoveEmptyEntries).Where(s => !string.IsNullOrWhiteSpace(s)).ToList();
- input = Regex.Replace(input, " ", "");
- string pattern = @"[0-9.]+";
- string[] math = Regex.Split(input, pattern);
- decimal count = decimal.Parse(nums[0]);
- for (int i = 0; i < math.Length; i++)
- {
- if (math[i] == "+")
- {
- count += decimal.Parse(nums[i]);
- }
- else if (math[i] == "-")
- {
- count -= decimal.Parse(nums[i]);
- }
- else if (math[i] == "*")
- {
- count *= decimal.Parse(nums[i]);
- }
- else if (math[i] == "/")
- {
- count /= decimal.Parse(nums[i]);
- }
- }
- Console.WriteLine("{0:F9}", count);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement