[백준] C# : 시험 성적 (9498번)

ssu_hyun·2022년 7월 6일
0

Data Structure & Algorithm

목록 보기
15/67
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Baekjoon
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            int score = int.Parse(s);

            if (90 <= score && score <= 100) { Console.WriteLine("A"); }
            else if (80 <= score && score <= 89) { Console.WriteLine("B"); }
            else if (70 <= score && score <= 79) { Console.WriteLine("C"); }
            else if (60 <= score && score <= 69) { Console.WriteLine("D"); }
            else { Console.WriteLine("F"); }
            
            //if (x >= 90)
			//{
			//    Console.WriteLine("A");
			//}
			//else if (x >= 80)
			//{
			//    Console.WriteLine("B");
			//}
			//else if (x >= 70)
			//{
			//    Console.WriteLine("C");
			//}
			//else if (x >= 60)
			//{
			//    Console.WriteLine("D");
			//}
			//else
			//{
			//    Console.WriteLine("F");
			//}   
        }
    }
}

// 방법2
// (Enumerable.Range(1,100).Contains(x))
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Baekjoon
{
    class Program
    {
        static void Main(string[] args)
        {
            // 입력 + 형변환
            int x = int.Parse(Console.ReadLine());
            
            // 1의 자리 버리고 숫자 동일하게 설정
            int score = (int)(Math.Truncate(input/10.0)*10);
            
            // 문자열 선언 + switch문
            string grade = score switch
            {
            	100 => "A",
                90 => "A",
                80 => "B",
                70 => "C",
                60 => "D",
                _ => "F"
            };
            
            Console.WriteLine(grade);
        }
    }
}

0개의 댓글