본문 바로가기

C#

[백준] 1330번 두 수 비교하기 C# 풀이

두 정수 A, B를 비교하는 프로그램을 작성하는 문제로 if문을 이용하여 푸는 문제이다.

 

A,B의 제한때문에 if문을 더 작성하였는데 해당 if문은 작성하지 않아도 채점에는 무방할 것 같다.

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
using System;
public class MainClass
{
    public static void Main()
    {
        string value = Console.ReadLine();
        string[] result = value.Split(' ');
 
        int a = Convert.ToInt32(result[0]);
        int b = Convert.ToInt32(result[1]);
 
        if (CheckValue(a) && CheckValue(b))
        {
            if (a > b)
            {
                Console.WriteLine(">");
            }
            else if (a < b)
            {
                Console.WriteLine("<");
            }
            else if (a == b)
            {
                Console.WriteLine("==");
            }
        }
    }
 
    private static bool CheckValue(int value)
    {
        if (value >= -10000 && value <= 10000)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
}
cs