Post

[BaekJoon] #31611 - 火曜日 (Tuesday) [Java][C++]

[BaekJoon] #31611 - 火曜日 (Tuesday) [Java][C++]

문제 링크


1. 아이디어

오늘이 일요일일 때, $X$일 후가 화요일인지 판단하는 문제로 7일 단위로 다시 일요일이 되므로 $X$를 7로 나눈 나머지가 2면 화요일이다.


2. 복잡도

접근시간공간
풀이$O(1)$$O(1)$

3. 코드

풀이 [Java][C++]

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import java.io.*;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        int x = Integer.parseInt(br.readLine());

        if (x % 7 == 2) {
            System.out.println(1);
        } else {
            System.out.println(0);
        }
    }
}
1
2
3
4
5
6
7
8
9
10
11
#include <bits/stdc++.h>
using namespace std;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int x;
    cin >> x;
    cout << (x % 7 == 2);
}

This post is licensed under CC BY 4.0 by the author.