본문 바로가기

Programming/Tutoring

윤년 참고 코드

#include "stdafx.h"

#include <stdio.h>



int main(){

int year, month, day, total_Day = 0, today=0;

int yoill;


printf_s("년 월 일 입력 : ");

scanf_s("%d %d %d", &year, &month, &day);


printf_s("\n%d년 %d월 %d일\n\n", year, month, day);


//((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) ? printf_s("윤년\n") : printf_s("평년\n");

bool a = ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) ? 1 : 0;

if (a)

printf_s("윤년\n");

else

printf_s("평년\n");


for (int i = 1; i < month; i++) {

if (i == 4 || i == 6 || i == 9 || i == 11) {

total_Day = total_Day + 30;

}

else if (i == 2) {

if (a) {

total_Day = total_Day + 29;

continue;

}

total_Day = total_Day + 28;

}

else

total_Day = total_Day + 31;

}

total_Day = total_Day + day;

today = total_Day;

printf("%d년의 %d일\n", year, today);

for (int i = 1900; i < year; i++) {

if (((i % 4 == 0 && i % 100 != 0) || i % 400 == 0))

total_Day += 366;

else

total_Day += 365;

}

yoill = (total_Day) % 7 -1;


char s[100] = "montuewedthufrisatsun";

printf_s("%d\n",yoill);

printf_s("%c%c%c\n\n\n\n", s[yoill * 3], s[yoill * 3 + 1], s[yoill * 3 + 2]);

printf_s("%d", total_Day);


return 0;

}

################################################################################

################################################################################

################################################################################

################################################################################

################################################################################

################################################################################

################################################################################

################################################################################



total_Day = 0

calendar = input("년 월 일 입력 : ")
year, month, day = calendar.split(' ')
year, month, day = int(year), int(month), int(day)
print("today is ", year, month, day)

arr = (4,6,8,11)
for i in range(2,month+1):
if i in arr:
total_Day += 30
elif i==2:
if i%4 == 0:
if i%100 == 0:
if i %400 == 0:
total_Day += 29
continue
total_Day += 28
continue
total_Day += 29
continue
total_Day += 31
else:
total_Day += 31
print("i is ",i)

total_Day += day
print(total_Day, "일")
yoill = total_Day % 7
day_of_week = "월화수목금토일"
print("today is ", day_of_week[yoill], "요일")





total_Day = 0


calendar = input("년 월 일 입력 : ")

year, month, day = calendar.split(' ')

year, month, day = int(year), int(month), int(day)

print("today is ", year, month, day)


arr = (4,6,8,11)

for i in range(2,month+1):

    if i in arr:

        total_Day += 30

    elif i==2:

        if i%4 == 0:

            if i%100 == 0:

                if i %400 == 0:

                    total_Day += 29

                    continue

                total_Day += 28

                continue

            total_Day += 29

            continue

        total_Day += 31

    else:

        total_Day += 31

    print("i is ",i)


total_Day += day

print(total_Day, "일")

yoill = total_Day % 7

day_of_week = "월화수목금토일"

print("today is ", day_of_week[yoill], "요일")



'Programming > Tutoring' 카테고리의 다른 글

백준  (0) 2019.05.07
윤년 답안 - 함수로 분할  (0) 2019.04.02
공모전  (0) 2019.04.02
1주차 - 답안  (0) 2019.03.26
1주차 - 윤년 && 선택정렬  (0) 2019.03.26