SWEA_D3_5515
π [D3_5515] 2016λ μμΌ λ§μΆκΈ°
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Solution {
// 1μ λΆν° 12μ κΉμ§ μΌμ
static int[] days = { 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
public static void main(String[] args) throws IOException {
StringTokenizer st = null;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();
// ν
μ€νΈ μΌμ΄μ€
int TC = Integer.parseInt(br.readLine());
for (int tc = 1; tc <= TC; tc++) {
st = new StringTokenizer(br.readLine(), " ");
// μ
int month = Integer.parseInt(st.nextToken());
// μΌ
int day = Integer.parseInt(st.nextToken());
// μμΌ κ° ( μ²μ κΈμμΌ = 4 )
int ans = 4;
// μΌ μ
int res = 0;
// 1μμΈ κ²½μ°
if (month == 1) {
res = day - 1;
}
// 1μ μ μΈ λλ¨Έμ§ λ¬
else {
for (int i = 2; i < month; i++) {
res += days[i];
}
// 1μ λλ¨Έμ§ κ° ( 30 ) + λ§μ§λ§ λ¬ day
res += (30 + day);
}
// μμΌ κ³μ°
int temp = res % 7;
// 0 ~ 6
if (temp <= 2) {
ans += temp;
} else {
ans = ans + temp - 7;
}
sb.append("#").append(tc).append(" ").append(ans).append("\n");
}
System.out.println(sb);
}
}
π€ λμ μκ°
7μ λ°°μλ₯Ό μ΄μ©νλ κ²μ΄ key point μλ κ² κ°λ€.
2016λ
μμμλ§ λ μ§λ₯Ό μ΄λν΄μ λΉκ΅μ μ΄λ ΅μ§ μμ λ¬Έμ μΈ κ² κ°λ€.