본문 바로가기
카테고리 없음

백준#5073 2023-09-06

by 하타라시 2023. 9. 6.

using System.Text;

StringBuilder stringBuilder = new StringBuilder();

    while(true) {

        //입력 받기
        string[] puts = Console.ReadLine().Split();
        int f = int.Parse(puts[0]);
        int s = int.Parse(puts[1]);
        int t = int.Parse(puts[2]);

        if(f+s+t == 0)
            break;

        int max = 0;

        //가장 큰 값 찾기
        if(f > max)
            max = f;
        if(s > max)
            max = s;
        if(t > max)
            max = t;
        

        //if문 그대로 해석
        int sum = f + s + t ;
        if(sum - max > max) {
            if(sum % max == 0){
                stringBuilder.AppendLine("Equilateral");
            } else if(f == s || s == t || f == t){
                stringBuilder.AppendLine("Isosceles");
            } else {
                stringBuilder.AppendLine("Scalene");
            }
        } else {
            stringBuilder.AppendLine("Invalid");
        }
    }
    Console.Write(stringBuilder);

 

 

개선 해보려고 했는데 오히려 속도가 느려져서 64ms로 만족하기로 했습니다,,

---------------------------------------------------------------------------------------------------------

using System.Text;

StringBuilder stringBuilder = new StringBuilder();

    while(true) {
        string[] puts = Console.ReadLine().Split();
        int f = int.Parse(puts[0]);
        int s = int.Parse(puts[1]);
        int t = int.Parse(puts[2]);

        if(f+s+t == 0)
            break;

        int max = 0;

        //가장 큰 값 찾기
        if(f > max)
            max = f;
        if(s > max)
            max = s;
        if(t > max)
            max = t;
        
        int sum = f + s + t ;
        if(sum - max <= max) {
            stringBuilder.AppendLine("Invalid");
        } else {
            if(sum == max * 3){
                stringBuilder.AppendLine("Equilateral");
            } else if(f == s || s == t || f == t){
                stringBuilder.AppendLine("Isosceles");
            } else {
                stringBuilder.AppendLine("Scalene");
            }
        }
    }
    Console.Write(stringBuilder);