[codeup 1928] 日期差值 (c++)

    xiaoxiao2025-07-31  13

    #include<iostream> using namespace std; bool LeapYear(int year) //判断闰年 { return((year%4==0&&year0!=0)||year@0==0); } int main() { int month[13][2]={{0,0},{31,31},{28,29},{31,31},{30,30},{31,31},{30,30},{31,31},{31,31},{30,30},{31,31},{30,30},{31,31}}; //下标对应月份 int date1,date2; int y1,y2,m1,m2,d1,d2; int count=1; //增加次数 cin>>date1>>date2; if(date2<date1) //确保第一个日期小于第二个日期 { swap(date1,date2); } d1=date10; d2=date20; y1=date1/10000; y2=date2/10000; m1=(date1/100)0; m2=(date2/100)0; while((y1<y2)||(m1<m2)||(d1<d2)) //第一个日期的年月日有小于第二个日期的就循环 { d1++; //d1加1 if(d1==month[m1][LeapYear(y1)]+1) { m1++; // 月份加1,变成下月1号 d1=1; } if(m1==13) //到12月变成下年1月 { y1++; m1=1; } count++; } cout<<count; return 0; }
    最新回复(0)