BOJ 9498 시험 성적

Ykhwong (토론 | 기여)님의 2018년 7월 31일 (화) 10:57 판

1 개요

BOJ 단계별로 풀어보기
순번 문제 풀이

틀:BOJ 4단계 틀:BOJ 단계 푸터

BOJ 9498 시험 성적

[[분류:BOJ {{{단계}}}단계]]

  • 시험 점수를 입력받고 성적 출력해보기
  • 알고리즘 분류: 구현

2 CMD

@echo off
set /p line=
if %line% gtr 90 echo A&& goto x
if %line% gtr 80 echo B&& goto x
if %line% gtr 70 echo C&& goto x
if %line% gtr 60 echo D&& goto x
echo F
:x

3 Go

package main
import "fmt"
func main() {
    var a int
    fmt.Scanf("%d", &a)
    if a >= 90 {
        fmt.Println("A")
    } else if a >= 80 {
        fmt.Println("B")
    } else if a >= 70 {
        fmt.Println("C")
    } else if a >= 60 {
        fmt.Println("D")
    } else {
        fmt.Println("F")
    }
}

4 Java

import java.util.Scanner;
public class Main {
    private static String getGrade(int score) {
        if( score >= 90 ) return "A";
        if( score >= 80 ) return "B";
        if( score >= 70 ) return "C";
        if( score >= 60 ) return "D";
        return "F";
    }
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int score = sc.nextInt();
        System.out.print(getGrade(score));
    }
}

5 Perl

while (<>) {
    die("A\n") if ( $_ >= 90 );
    die("B\n") if ( $_ >= 80 );
    die("C\n") if ( $_ >= 70 );
    die("D\n") if ( $_ >= 60 );
    die("F\n");
}

6 PHP

<?php
function get_grade($score) {
    if( $score >= 90 ) return 'A';
    if( $score >= 80 ) return 'B';
    if( $score >= 70 ) return 'C';
    if( $score >= 60 ) return 'D';
    return 'F';
}
fscanf(STDIN,"%d",$score);
echo get_grade($score);

7 Python

score = int(input())
if score >= 90:
    print( 'A' )
elif score >= 80:
    print( 'B' )
elif score >= 70:
    print( 'C' )
elif score >= 60:
    print( 'D' )
else:
    print( 'F' )
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}