CodeLabs

[백준 / C#] 1541 : 잃어버린 괄호 본문

백준/1000 ~

[백준 / C#] 1541 : 잃어버린 괄호

무오_ 2023. 7. 13. 18:35
using System;

class Program
{
    static string[] str;
    static int result = 0;
    static void Input()
    {
        str = Console.ReadLine().Split('-');
    }
    static void Solution()
    {
        Division();
        for(int i=1; i<str.Length; i++)
        {
            if (str[i].Contains("+"))
            {
                string[] copy = str[i].Split('+');
                for (int j=0; j<copy.Length; j++)
                {
                    result -= int.Parse(copy[j]);
                }
            }
            else
            {
                result -= int.Parse(str[i]);
            }
        }
        Console.WriteLine(result);
    }
    static void Division()
    {
        if (str[0].Contains("+"))
        {
            string[] div = str[0].Split('+');
            for (int i = 0; i < div.Length; i++)
                result += int.Parse(div[i]);
        }
        else
            result = int.Parse(str[0]);
    }
    static void Solve()
    {
        Input();
        Solution();
    }
    static void Main(string[] args)
    {
        Solve();
    }
}