백준 온라인 코딩 문제풀이
Baekjoon Online Judge
Baekjoon Online Judge 프로그래밍 문제를 풀고 온라인으로 채점받을 수 있는 곳입니다.
www.acmicpc.net
코드 참고
wny0320 (박 상운)
Run code live in your browser. Write and run code in 50+ languages online with Replit, a powerful IDE, compiler, & interpreter.
replit.com
2739, 10950, 8393, 25304 중 일부 문제에 대한 풀이
풀이가 없는 코드 확인은 replit 참고
10950
using System;
class Program
{
public static void Main(string[] args)
{
int time = Int32.Parse(Console.ReadLine());
int[] result = new int[time];
for (int i = 0; i < time; i++)
{
string[] num = Console.ReadLine().Split();
result[i] = (Int32.Parse(num[0]) + Int32.Parse(num[1]));
}
for (int i = 0; i < time; i++)
{
Console.WriteLine(result[i]);
}
}
}
주어진 반복 횟수를 time으로 잡고 Int형식으로 변환하여 저장
result 배열을 time의 크기만큼 만든 후 반복문 실행
주어진 숫자를 string 형식으로 Split하여 배열에 저장 후 Int로 변환하여 각각 result에 담아 한꺼번에 출력
25304
using System;
class Program
{
public static void Main(string[] args)
{
int price = Int32.Parse(Console.ReadLine());
int times = Int32.Parse(Console.ReadLine());
int result = 0;
for (int i = 0; i < times; i++)
{
string[] buffer = Console.ReadLine().Split();
result += (Int32.Parse(buffer[0]) * Int32.Parse(buffer[1]));
}
if (result == price)
{
Console.WriteLine("Yes");
}
else
{
Console.WriteLine("No");
}
}
}
총 가격과 반복 횟수를 받아 Int로 형변환 후 저장
반복 횟수만큼 buffer에 문자열 배열을 받아 저장
Int 형식으로 각각 변환하여 곱한 후 result에 더해줌
총 가격 price와 result가 같다면 Yes, 아니라면 No를 출력
사실 문제를 더 풀고 싶었지만 다음 문제인 15552가 깊게 이해할 필요성을 느껴 천천히 하고자 함
'BaekJoon[C#]' 카테고리의 다른 글
반복문 2439 (0) | 2022.09.19 |
---|---|
반복문 15552 (0) | 2022.09.18 |
조건문 2480 (0) | 2022.09.16 |
입출력과 사칙연산 2588 (0) | 2022.09.15 |
입출력과 사칙연산 10869 (0) | 2022.09.14 |