三天打渔,俩天晒网(C++实现)
#include <iostream>
using namespace std;
int leap (int a)
{
if (a%4==0%a%100!=0||a%400==0)
{
return 1;
}
else
{
return 0;
}
}
int number(int year,int month,int day)
{
int sum=0,i,j;
int a[12]={31,28,31,30,31,30,31,31,30,31,30,31};
int b[12]={31,29,31,30,31,30,31,31,30,31,30,31};
if (leap(year)==1)
{for (i=0;i <month-1;i++)
sum+=a[i];
}
else
for (i=0;i<month-1;i++)
sum+=b[i];
for (j=2011;j<year;j++)
if (leap(j)==1)
{
sum+=366;
}
else
{
sum+=365;
}
sum+=day;
return sum;
}
int main ()
{
int year,month,day,n;
cout<<"请输入年月日";
cin>>year>>month >>day;
n=number(year,month,day);
if ((n%5)<4&&(n%5)>0)
cout<<"打渔"<<year<<month<<day <<endl;
else
cout<<"晒网"<<year<<month<<day <<endl;
}
using namespace std;
int leap (int a)
{
if (a%4==0%a%100!=0||a%400==0)
{
return 1;
}
else
{
return 0;
}
}
int number(int year,int month,int day)
{
int sum=0,i,j;
int a[12]={31,28,31,30,31,30,31,31,30,31,30,31};
int b[12]={31,29,31,30,31,30,31,31,30,31,30,31};
if (leap(year)==1)
{for (i=0;i <month-1;i++)
sum+=a[i];
}
else
for (i=0;i<month-1;i++)
sum+=b[i];
for (j=2011;j<year;j++)
if (leap(j)==1)
{
sum+=366;
}
else
{
sum+=365;
}
sum+=day;
return sum;
}
int main ()
{
int year,month,day,n;
cout<<"请输入年月日";
cin>>year>>month >>day;
n=number(year,month,day);
if ((n%5)<4&&(n%5)>0)
cout<<"打渔"<<year<<month<<day <<endl;
else
cout<<"晒网"<<year<<month<<day <<endl;
}