标签:
简单模拟题
#include <iostream> #include <string> using namespace std; //判断是不是闰年 bool is(int year){ return year % 400 == 0?true: (year % 100 == 0?false:(year % 4 == 0?true:false)); } //判断结束日期是否不包括2月29 #define NO2 (in2Var1 < 3 && !(in2Var1 == 2 && in2Var2 == "29,")) //判断开始日期是否包括2月29 #define YES1 (in1Var1 < 3) int main(void) { int t; cin >> t; //月份列表 string str[] = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November" , "December"}; //输入月份 string in1Var0,in2Var0; //数值月份 int in1Var1,in2Var1; //输入日期 string in1Var2,in2Var2; //输入年份 int in1Var3,in2Var3; for(int i = 1; i <= t; ++i){ cin >> in1Var0 >> in1Var2 >> in1Var3; cin >> in2Var0 >> in2Var2 >> in2Var3; int count = 0; //月份从字符串换算到数值 for(int j = 0; j < 12; ++j){ if(in1Var0 == str[j]) in1Var1 = j+1; if(in2Var0 == str[j]) in2Var1 = j+1; } //对闰年的粗糙加减,从开始年份的末尾到结束年份的末尾. count += in2Var3/4 - in1Var3/4; count -= in2Var3/100 - in1Var3/100; count += in2Var3/400 - in1Var3/400; //判断开始年份是闰年且开始日期包括2月29 if(is(in1Var3) && YES1) ++count; //判断结束年份是闰年且结束日期不包括2月29 if(is(in2Var3) && NO2) --count; cout << "Case #" << i << ": " << count << endl; } return 0; }
标签:
原文地址:http://blog.csdn.net/lane_l/article/details/45117825