
1. 문제 풀이 아이디어
- 세 개의 값(E, S, M)이 주어진 범위를 반복하며 1씩 증가시키면서 조건을 만족하는 최소 연도를 찾아 문제를 해결한다.
2. 나의 정답 코드
using (StreamReader sr = new StreamReader(Console.OpenStandardInput()))
using (StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()))
{
int[] esm = Array.ConvertAll(sr.ReadLine().Split(), int.Parse);
int e = 1;
int s = 1;
int m = 1;
int result = 1;
while (e != esm[0] || s != esm[1] || m != esm[2])
{
e = ++e > 15 ? 1 : e;
s = ++s > 28 ? 1 : s;
m = ++m > 19 ? 1 : m;
result++;
}
sw.WriteLine(result);
}
3. 정리
sr.ReadLine().Split()
로 입력값을 공백 기준으로 나눈 후int.Parse
를 사용해 정수 배열로 변환한다.
e
,s
,m
을 각각 1로 초기화하고,result
를 1부터 시작한다.
while
루프에서e
,s
,m
이 입력값과 일치할 때까지 반복한다.
e
,s
,m
을 각각 1씩 증가시키되, 각 값이 초과하면 다시 1로 순환하도록 한다.
- 조건을 만족하면
result
값을 출력한다.
Share article