![정수 배열 date1과 date2가 주어집니다. 두 배열은 각각 날짜를 나타내며 [year, month, day] 꼴로 주어집니다. 각 배열에서 year는 연도를, month는 월을, day는 날짜를 나타냅니다.
만약 date1이 date2보다 앞서는 날짜라면 1을, 아니면 0을 return 하는 solution 함수를 완성해 주세요.](http://t1.daumcdn.net/tistory_admin/static/images/no-image-v1.png)
문제 설명
정수 배열 date1과 date2가 주어집니다. 두 배열은 각각 날짜를 나타내며 [year, month, day] 꼴로 주어집니다. 각 배열에서 year는 연도를, month는 월을, day는 날짜를 나타냅니다.
만약 date1이 date2보다 앞서는 날짜라면 1을, 아니면 0을 return 하는 solution 함수를 완성해 주세요.
제한사항
- date1의 길이 = date2의 길이 = 3
- 0 ≤ year ≤ 10,000
- 1 ≤ month ≤ 12
- day는 month에 따라 가능한 날짜로 주어집니다.
입출력 예
date1 | date2 | result |
[2021, 12, 28] | [2021, 12, 29] | 1 |
[1024, 10, 24] | [1024, 10, 24] | 0 |
C++ 코딩테스트 날짜 비교하기
#include <string>
#include <vector>
using namespace std;
int solution(vector<int> date1, vector<int> date2) {
int answer = 0;
for(int i = 0; i < 3; ++i) {
if(date1[i] < date2[i]) {
answer = 1;
break;
}
else if(date1[i] > date2[i]) {
break;
}
}
return answer;
}
댓글