BOJ 1924 2007년

Jmnote (토론 | 기여)님의 2023년 8월 26일 (토) 13:18 판
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)

1 개요[ | ]

BOJ 1924 2007년
  • 2007년 x월 y일이 무슨 요일인지 알아내보기
  • 2007년도 어느 날의 요일의 규칙을 찾아 출력하는 문제

2 C[ | ]

#include <stdio.h>
void main()
{
    int ends[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    char *weekdays[] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
    int month, day, ordinal = 0;
    int i, j;
    scanf("%d %d", &month, &day);
    for (i = 0; i < month-1; i++) {
        ordinal += ends[i];
    }
    ordinal += day;
    printf("%s\n", weekdays[ordinal%7]);
}

3 C++[ | ]

#include <iostream>
#include <cstring>
using namespace std;
int main() {
    int ends[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    string weekdays[] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
    int month, day, ordinal = 0;
    int i, j;
    scanf("%d %d", &month, &day);
    for (i = 0; i < month-1; i++) ordinal += ends[i];
    ordinal += day;
    cout << weekdays[ordinal%7] << endl;
}

4 Java[ | ]

import java.util.*;
public class Main {
    public static void main(String args[]) {
        int[] ends = {31,28,31,30,31,30,31,31,30,31,30,31};
        String[] weekdays = {"SUN","MON","TUE","WED","THU","FRI","SAT"};
        
        Scanner sc = new Scanner(System.in);
        int month = sc.nextInt();
        int day = sc.nextInt();
        
        int ordinal = 0;
        for(int i=0; i<month-1; i++) {
            ordinal += ends[i];
        }
        ordinal += day;
        System.out.print(weekdays[ordinal%7]);
    }
}

5 Perl[ | ]

@ends = (31,28,31,30,31,30,31,31,30,31,30,31);
@weekdays = ("SUN","MON","TUE","WED","THU","FRI","SAT");

($month, $day) = split / /, <>;
$ordinal = 0;
for( $i=0; $i<$month-1; $i++ ) {
    $ordinal += $ends[$i];
}
$ordinal += $day;
print $weekdays[$ordinal%7] . "\n";

6 PHP[ | ]

<?php
$ends = [31,28,31,30,31,30,31,31,30,31,30,31];
$weekdays = ["SUN","MON","TUE","WED","THU","FRI","SAT"];

fscanf(STDIN,"%d %d",$month,$day);
$ordinal = 0;
for( $i=0; $i<$month-1; $i++ ) {
    $ordinal += $ends[$i];
}
$ordinal += $day;
echo $weekdays[$ordinal%7];

7 Python[ | ]

ends = [31,28,31,30,31,30,31,31,30,31,30,31]
weekdays = ["SUN","MON","TUE","WED","THU","FRI","SAT"]

month, day = map(int,input().split())
ordinal = 0
for i in range(month-1):
    ordinal += ends[i]
ordinal += day
print( weekdays[ordinal%7] )
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}