Cześć ostatnio dostałem takie zadanie:
Write a C# console application that evaluates a string expression consisting of
non-negative integers and the + - / * operators only, taking into account the normal
mathematical rules of operator precedence. Support for brackets is not required.
For example:
an input string of "4+5*2" should output 14
an input string of "4+5/2" should output 6.5
an input string of "4+5/2-1" should output 5.5
Submission:
Please send us your source code in a format that we can easily compile along with a brief description of how you approached the problem and the decisions you made in order to make our solution well thought out, maintainable and production quality. Please compress your source code into a single archive (*.ZIP only) and don’t include any binaries.
a moje wyknaniego tego zadania wygląda tak xd
Uznają mnie za idiotę bo kurcze nie ma ngidzie ze nie mogę używać bibliotek xd
class Program
{
static void Main(string[] args)
{
//Skorzystałem z biblioteki https://github.com/mariuszgromada/MathParser.org-mXparser
string a = Console.ReadLine(); // Pobranie wartości
double score = Calculator.Calculate(a); // Wyliczenie wyniku
Console.WriteLine(score); // Wyświetlenie wyniku na ekaranie
}
}
public class Calculator
{
public static double Calculate(string task)
{
Expression e = new Expression(task);
double score = e.calculate();
return score;
}
}