追海逐风

导航

细节决定成败

such an easy problem that I didn't AC. WA 4 times.

Problem:

Judge if the (m, d) is a valid date, the year is 2010.

1. 2010 is not a leap year, so February has only 28 days.

2. Negative numbers must be considered.

#include <iostream>

using namespace std;

const int DAYS[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

int main() {
	int n;
	cin >> n;
	while (n--) {
		int m, d;
		cin >> m >> d;
		cout << ((m < 1 || m > 12 || d < 1 || d > DAYS[m]) ? "No" : "Maybe") << endl;
	}
}

posted on 2010-09-25 13:21  追海逐风  阅读(208)  评论(0编辑  收藏  举报