๐ฉ๐ปProgramming/Coding Test
[C#] [BOJ#2445] ์ง๋ฅํ ๊ธฐ์ฐจ
taesooya
2022. 8. 14. 15:06
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);
}
}