상세 컨텐츠

본문 제목

백준#9498-시험 성적

C#/알고리즘

by McRobbin 2020. 4. 6. 18:22

본문

https://www.acmicpc.net/problem/9498

 

9498번: 시험 성적

시험 점수를 입력받아 90 ~ 100점은 A, 80 ~ 89점은 B, 70 ~ 79점은 C, 60 ~ 69점은 D, 나머지 점수는 F를 출력하는 프로그램을 작성하시오.

www.acmicpc.net

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace _9498
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] grades = { "F""F""F""F""F""F""D""C""B""A""A" };
            Console.WriteLine(grades[int.Parse(Console.ReadLine()) / 10]);
        }
    }
}
 
 
 

if 문의 처리가 많을 것으로 예상되어 배열로 Grade값을 일일히 넣어주는 것이 빠를거라 생각했습니다.

입력 받은 값을 int로 변환, 10으로 나눈 몫을 가져와 십의 자리를 인덱스로 Grade를 출력하도록 했습니다.

'C# > 알고리즘' 카테고리의 다른 글

백준#10951 - A+B - 4  (0) 2020.04.08
백준#10952-A+B - 5  (0) 2020.04.08
백준#1931-회의실배정  (0) 2020.04.07
백준#11047-동전 0  (0) 2020.04.07
백준#11399-ATM  (0) 2020.04.07

관련글 더보기