c# 백준 5073 삼각형과 세 변.
풀이 과정
if else문을 통해서 조건 하나하나씩 판별하였음
전체 코드
class Program
{
static void Main(string[] args)
{
while (true)
{
string s = Console.ReadLine();
if (s == "0 0 0") break;
string[] sArr = s.Split();
int[] length = new int[3];
for (int i = 0; i < 3; i++)
{
length[i] = int.Parse(sArr[i]);
}
// 삼각형이 아닐 경우
if(length.Max() >= length[0] + length[1] + length[2] - length.Max())
{
Console.WriteLine("Invalid");
}
// 세 변이 같을 경우
else if (length[0] == length[1] && length[0] == length[2])
{
Console.WriteLine("Equilateral");
}
// 두 변이 같을 경우
else if(length[0] == length[1] || length[0] == length[2] || length[1] == length[2])
{
Console.WriteLine("Isosceles");
}
// 모든 변의 길이가 서로 같지 않을 경우
else
{
Console.WriteLine("Scalene");
}
}
}
}
댓글남기기