๐Ÿ‘ฉ‍๐Ÿ’ปProgramming/Coding Test

[C#] [BOJ#2445] ์ง€๋Šฅํ˜• ๊ธฐ์ฐจ

taesooya 2022. 8. 14.

https://www.acmicpc.net/problem/2455

 

2455๋ฒˆ: ์ง€๋Šฅํ˜• ๊ธฐ์ฐจ

์ตœ๊ทผ์— ๊ฐœ๋ฐœ๋œ ์ง€๋Šฅํ˜• ๊ธฐ์ฐจ๊ฐ€ 1๋ฒˆ์—ญ(์ถœ๋ฐœ์—ญ)๋ถ€ํ„ฐ 4๋ฒˆ์—ญ(์ข…์ฐฉ์—ญ)๊นŒ์ง€ 4๊ฐœ์˜ ์ •์ฐจ์—ญ์ด ์žˆ๋Š” ๋…ธ์„ ์—์„œ ์šดํ–‰๋˜๊ณ  ์žˆ๋‹ค. ์ด ๊ธฐ์ฐจ์—๋Š” ํƒ€๊ฑฐ๋‚˜ ๋‚ด๋ฆฌ๋Š” ์‚ฌ๋žŒ ์ˆ˜๋ฅผ ์ž๋™์œผ๋กœ ์ธ์‹ํ•  ์ˆ˜ ์žˆ๋Š” ์žฅ์น˜๊ฐ€ ์žˆ๋‹ค.

www.acmicpc.net

My Solution


using System;
using System.Linq;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] result = new int[5];
            result[0] = 0;
            for (int i = 1; i < 5; i++)
            {
                int[] n = Array.ConvertAll<string, int>(Console.ReadLine().Split(), int.Parse);
                int input = n[1];
                int output = n[0];
                result[i] = result[i - 1] + input - output;
            }
            Console.WriteLine(result.Max());
        }
    }
}

Solution

  • if(max<count) max = count๋กœ ์ตœ๋Œ€๊ฐ’ ๊ฐฑ์‹ !! ๊ฐ„๋‹จํ•œ ์ˆ˜ํ•™,,

using static System.Console;

class Program
{
    static void Main() {
        int max = 0;
        int count = 0;
        
        for(int i=0; i<4; i++){
            string[] r = ReadLine().Split(' ');
            
            count = count - int.Parse(r[0]);
            count = count + int.Parse(r[1]);
            if (max < count)
            max = count;
        }
        WriteLine(max);
    }
}

๋Œ“๊ธ€