运用数组来解决数据叠加问题,以月为条件,来依次增加天数,用if语句来判断年份是否为闰年,若为闰年则2月为29天,在输入/时,加入char型来输入。
...
include<iostream>
using namespace std;
int main()
{
int n, m, r;
char z, c;
while (cin >> n>>z >> m >>c>> r)
{
int a[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };
if (n % 400 == 0 || (n % 4 == 0 && n % 100 != 0))
{
a[1] = 29;
}
int i = 0;
int x = 0;
while (i < m - 1)
{
x = x + a[i];
i++;
}
int y;
y = x + r;
cout << y << endl;
}
return 0;
}
...
网友评论