[ 문제 ] : https://www.acmicpc.net/problem/1924

 

1924번: 2007년

첫째 줄에 빈 칸을 사이에 두고 x(1 ≤ x ≤ 12)와 y(1 ≤ y ≤ 31)이 주어진다. 참고로 2007년에는 1, 3, 5, 7, 8, 10, 12월은 31일까지, 4, 6, 9, 11월은 30일까지, 2월은 28일까지 있다.

www.acmicpc.net


[ 문제 접근 ]

 

문제 풀이를 하면 할수록 입출력에 아직 부족함을 많이 느끼고 기본 문제들을 하루에 몇 개씩이라도 풀어보려고한다.


[ 첫번째 코드 ]

#include<iostream>
using std::cout; using std::cin;

int month, day;
enum DAY {
	SUN = 0,
	MON,
	TUE,
	WED,THU,FRI,SAT
};

int main() {
	std::ios::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);
	
	cin >> month >> day;

	for (int i = 1; i < month; i++) {
		if (i == 2) {
			day += 28;
		}
		else if (i == 4 || i == 6 || i == 9 || i == 11) {
			day += 30;
		}
		else {
			day += 31;
		}
	}

	if ((day % 7) == SUN) cout << "SUN";
	else if ((day % 7) == MON) cout << "MON";
	else if ((day % 7) == TUE) cout << "TUE";
	else if ((day % 7) == WED) cout << "WED";
	else if ((day % 7) == THU) cout << "THU";
	else if ((day % 7) == FRI) cout << "FRI";
	else if ((day % 7) == SAT) cout << "SAT";

	return 0;
}

[ 두번째 코드 ]

 

#include<iostream>
#include<string>

using std::cout; using std::cin;

int month, day;
std::string days[] = { "SUN","MON","TUE","WED","THU","FRI","SAT" };
int months[] = { 31,28,31,30,31,30,31,31,30,31,30,31 };

int main() {
	std::ios::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);
	
	cin >> month >> day;

	for (int i = 0; i < month - 1; i++) {
		day += months[i];
	}
	int key = day % 7;

	cout << days[key];
	
	return 0;
}

[ Key Point ]

 

👉 무식하게 풀었다가 다른 사람의 풀이를 깔끔하게 고쳤다.

     이런 기본적인 부분이 아직 부족하다고 느낀다.

 


[ 다른 사람 풀이 ]

 

ref : https://blockdmask.tistory.com/247

+ Recent posts