본문 바로가기

컴퓨터 과학/자료구조, 알고리즘

[Rust로 백준 하루 하나] 2-1. 두 수 비교하기

문제 (1330번)

두 정수 A와 B가 주어졌을 때, A와 B를 비교하는 프로그램을 작성하시오.

 

입력

첫째 줄에 A와 B가 주어진다. A와 B는 공백 한 칸으로 구분되어져 있다.

 

출력

첫째 줄에 다음 세 가지 중 하나를 출력한다.

  • A가 B보다 큰 경우에는 '>'를 출력한다.
  • A가 B보다 작은 경우에는 '<'를 출력한다.
  • A와 B가 같은 경우에는 '=='를 출력한다.

풀이

코드

use std::io;

fn main() {
    let mut input = String::new();
    io::stdin()
        .read_line(&mut input)
        .expect("Cannot read line.");

    let input: Vec<&str> = input.split_whitespace().collect();
    let a: i32 = input[0].trim().parse().unwrap();
    let b: i32 = input[1].trim().parse().unwrap();

    if a > b {
        println!(">");
    } else if a < b {
        println!("<");
    } else {
        println!("==");
    }
}

해설


추가 학습

  • 특이사항 없음