배열로 푸는 방법
using System;
using System.Linq;
namespace codingstudy
{
class Program
{
static void Main()
{
int[] num = new int[31]; // 30까지 숫자 넣을 배열 만들어줌
for (int i = 0; i < 28; i++) // 28개의 숫자 입력해주고
{
int n = int.Parse(Console.ReadLine());
num[n] = 1; // 그 배열 값을 1로 만들어줌
}
for (int i = 1; i <= 30; i++)
{
if (num[i] != 1) // 배열 값이 1인지 아닌지해서 아니면 출력
{
Console.WriteLine(i);
}
}
}
}
}
Linq 리스트로 푸는 방법
using System;
using System.Linq;
namespace codingstudy
{
class Program
{
static void Main()
{
List<int> num = Enumerable.Range(0, 30).ToList();
for (int i = 0; i < 28; i++)
{
int n = int.Parse(Console.ReadLine());
num.Remove(n);
}
num.Sort();
Console.WriteLine(num[0]);
Console.WriteLine(num[1]);
}
}
}
[Enumerable 클래스로 컬렉션 만들기]
System.Linq 네임스페이스에 들어 있음
Range()와 Repeat() 메서드를 제공
특정 범위의 정수 컬렉션을 손쉽게 만들 수 있음
'C# > C# (백준)' 카테고리의 다른 글
[C#] 백준 알고리즘 4673번, 셀프 넘버 (0) | 2023.02.10 |
---|---|
[C#] 백준 알고리즘 4344번, 평균은 넘겠지 (0) | 2023.02.07 |
[C#] 백준 알고리즘 10807번, 개수 세기 (0) | 2023.01.31 |
[C#] 백준 알고리즘 10951번, A+B - 4 (0) | 2023.01.12 |
[C#] 백준 알고리즘 10952번, A+B - 5 (0) | 2023.01.12 |