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

 
(사용자 3명의 중간 판 6개는 보이지 않습니다)
1번째 줄: 1번째 줄:
[[분류:BOJ 4단계|1]]
==개요==
==개요==
* {{BOJ|9498}}
{{BOJ|단계=2}}
* 시험 점수를 입력받고 성적 출력해보기
* 시험 점수를 입력받고 성적 출력해보기
* 알고리즘 분류: 구현
* 알고리즘 분류: 구현


{{BOJ 단계 헤더}}
==C++==
{{BOJ 4단계}}
<syntaxhighlight lang='cpp'>
{{BOJ 단계 푸터}}
#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";
}
</syntaxhighlight>


==CMD==
==CMD==
<source lang='dos'>
<syntaxhighlight lang='dos'>
@echo off
@echo off
set /p line=
set /p line=
19번째 줄: 29번째 줄:
echo F
echo F
:x
:x
</source>
</syntaxhighlight>


==Go==
==Go==
<source lang='go'>
<syntaxhighlight lang='go'>
package main
package main
import "fmt"
import "fmt"
40번째 줄: 50번째 줄:
     }
     }
}
}
</source>
</syntaxhighlight>


==Java==
==Java==
<source lang='Java'>
<syntaxhighlight lang='Java'>
import java.util.Scanner;
import java.util.Scanner;
public class Main {
public class Main {
59번째 줄: 69번째 줄:
     }
     }
}
}
</source>
</syntaxhighlight>


==Perl==
==Perl==
<source lang='python'>
<syntaxhighlight lang='python'>
while (<>) {
while (<>) {
     die("A\n") if ( $_ >= 90 );
     die("A\n") if ( $_ >= 90 );
70번째 줄: 80번째 줄:
     die("F\n");
     die("F\n");
}
}
</source>
</syntaxhighlight>


==PHP==
==PHP==
<source lang='PHP'>
<syntaxhighlight lang='PHP'>
<?php
<?php
function get_grade($score) {
function get_grade($score) {
84번째 줄: 94번째 줄:
fscanf(STDIN,"%d",$score);
fscanf(STDIN,"%d",$score);
echo get_grade($score);
echo get_grade($score);
</source>
</syntaxhighlight>


==Python==
==Python==
<source lang='python'>
<syntaxhighlight lang='python'>
score = int(input())
score = int(input())
if score >= 90:
if score >= 90:
99번째 줄: 109번째 줄:
else:
else:
     print( 'F' )
     print( 'F' )
</source>
</syntaxhighlight>

2023년 8월 26일 (토) 13:10 기준 최신판

1 개요[ | ]

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

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

3 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

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

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

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

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

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