"BOJ 9498 시험 성적"의 두 판 사이의 차이

잔글 (봇: 자동으로 텍스트 교체 (-</source> +</syntaxhighlight>, -<source +<syntaxhighlight ))
1번째 줄: 1번째 줄:
[[분류:BOJ 4단계|1]]
[[분류:BOJ 4단계|1]]
==개요==
==개요==
* {{BOJ|9498}}
* {{BOJ|단계=4}}
* 시험 점수를 입력받고 성적 출력해보기
* 시험 점수를 입력받고 성적 출력해보기
* 알고리즘 분류: 구현
* 알고리즘 분류: 구현
{{BOJ 단계 헤더}}
{{BOJ 4단계}}
{{BOJ 단계 푸터}}


==Bash==
==Bash==

2023년 8월 25일 (금) 19:39 판

1 개요

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

2 Bash

read n
if [ $n -gt 90 ]; then
    echo A
elif [ $n -gt 80 ]; then
    echo B
elif [ $n -gt 70 ]; then
    echo C
elif [ $n -gt 60 ]; then
    echo D
else
    echo F
fi

3 C++

#include <iostream>
using namespace std;
int main() {
    int score;
    scanf("%d", &score);
    if( score >= 90 ) cout << "A";
    else if( score >= 80 ) cout << "B";
    else if( score >= 70 ) cout << "C";
    else if( score >= 60 ) cout << "D";
    else cout << "F";
}

4 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

5 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")
    }
}

6 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));
    }
}

7 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");
}

8 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);

9 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 }}