[BOJ][1924] 2007년
Updated:
1. 문제 링크
https://www.acmicpc.net/problem/1924
2. 사용 알고리즘
구현
3. 풀이
총 일자수를 구한 후, 7로 나눈 나머지로 요일 계산
4. 소스 코드
4-1. C++
https://github.com/dev-aiden/problem-solving/blob/main/boj/1924.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>
#include <vector>
using namespace std;
vector<int> date = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
vector<string> day = { "SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT" };
int main(void) {
ios_base::sync_with_stdio(false);
int x, y; cin >> x >> y;
int sum = 0;
for (int i = 1; i < x; ++i) sum += date[i - 1];
sum += y;
cout << day[sum % 7] << '\n';
return 0;
}
4-2. JAVA
https://github.com/dev-aiden/problem-solving/blob/main/boj/1924.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
private static int[] date = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
private static String[] day = { "SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT" };
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine(), " ");
int x = Integer.parseInt(st.nextToken());
int y = Integer.parseInt(st.nextToken());
int sum = 0;
for (int i = 1; i < x; ++i) sum += date[i - 1];
sum += y;
System.out.println(day[sum % 7]);
}
}
Leave a comment