Coding Test/SW Expert Academy

[SWEA] 1948. 날짜 계산기 c++

owls 2022. 11. 18. 13:26
728x90
  • 문제

※ SW Expert 아카데미의 문제를 무단 복제하는 것을 금지합니다.

월 일로 이루어진 날짜를 2개 입력 받아, 두 번째 날짜가 첫 번째 날짜의 며칠째인지 출력하는 프로그램을 작성하라.

 

 

  • 문제 해결
#include<iostream>

using namespace std;

int day[13] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };

int main(int argc, char** argv)
{
	int test_case;
	int T;
	
	cin>>T;
	
	for(test_case = 1; test_case <= T; ++test_case)
	{

		int h1 = 0, m1 = 0, h2 = 0, m2 = 0;
        cin >> h1 >> m1 >> h2 >> m2;
        
        int result = day[h1] - m1 + 1;
        for(int i = h1 +1; i <= h2; i++){
        	result += day[i];
        }
		result -= ( day[h2] - m2);
        cout << "#" << test_case <<" " << result << endl;
	}
	return 0;
}
728x90