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.Numerics;
- using System.Globalization;
- using System.Text.RegularExpressions;
- namespace Problem01_PadawanEquipment
- {
- class MainClass
- {
- /* */
- public static void Main()
- {
- char[] sep = { ' ' };
- var input = Console.ReadLine()
- .Split(sep, StringSplitOptions.RemoveEmptyEntries)
- .ToList();
- List<double> numsFromInput = ExtractDoublesFromInput(input);
- bool addition = false;
- bool additionThenSubtraction = false;
- bool subtractionThenAddition = false;
- bool subtraction = false;
- double result = 0;
- for (int i = 0; i < input.Count; i++)
- {
- if(input[1] == "+"&& input[3] == "+")
- {
- addition = true;
- }
- else if(input[1] == "+" && input[3] == "-")
- {
- additionThenSubtraction = true;
- }
- else if(input[1] == "-" && input[3] == "+")
- {
- subtractionThenAddition = true;
- }
- else
- {
- subtraction = true;
- }
- }
- if(addition)
- {
- result = numsFromInput[0] + numsFromInput[1] + numsFromInput[2];
- Console.Write(result);
- }
- else if(additionThenSubtraction)
- {
- result = numsFromInput[0] + numsFromInput[1] - numsFromInput[2];
- Console.Write(result);
- }
- else if(subtractionThenAddition)
- {
- result = numsFromInput[0] - numsFromInput[1] + numsFromInput[2];
- Console.Write(result);
- }
- else if(subtraction)
- {
- result = numsFromInput[0] - numsFromInput[1] - numsFromInput[2];
- Console.Write(result);
- }
- else
- {
- Console.Write("Please enter numbers and the '+' or '-' signs.");
- }
- }
- public static List<double> ExtractDoublesFromInput(List<string> input)
- {
- List<double> doublesFromInput = new List<double>();
- doublesFromInput[0] = double.Parse(input[0].ToString());
- doublesFromInput[1] = double.Parse(input[2].ToString());
- doublesFromInput[2] = double.Parse(input[4].ToString());
- return doublesFromInput;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement