您的位置:首页 > 编程语言 > C语言/C++

我只是不想丢掉这个课堂作业

2017-10-10 16:59 281 查看
#include <iostream>
#include <cstring>
#include <algorithm>
#include <string>

using namespace std;

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

bool is_jumpyear (int n) {
if (n % 400 == 0 || (n % 100 != 0 && n % 4 == 0)) return true;
return false;
}

bool isRightYear (int y,int m,int d) {
if (y <= 0) {
cout << "The year must be a postive !\n";
return false;
}
if (m <= 0 || m > 12) {
cout << "The month must between 1 and 12 \n";
return false;
}
if (d <= 0) {
cout << "The day must greater than 0\n";
return false;
}
if (is_jumpyear(y)) month[2] = 29;
int limit_day = month[m];
if (d > limit_day) {
cout << "The day should not greater than " << limit_day << endl;
return false;
}
return true;
}
int main () {
ios_base :: sync_with_stdio(false);
int y,m,d;
while(cin >> y >> m >> d) {
if (isRightYear(y, m, d)) {
cout << "yes" << endl;
}
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  C++-作业