问题描述:中国有句俗语叫:“三天打鱼两天晒网”。某人从1990年1月1日起开始“三天打鱼两天晒网”,问这个人在以后的某一天中是“打鱼”还是“晒网”。
流程图:
伪代码:
input year,month,day
jianday<-0
for i<-1990 to year-1
if i是闰年
then jianday=jianday+366
else
jianday=jianday+365
int Month[13]<-{0,31,28,,31,30,31,30,31,31,30,31,30,31}
if year为闰年
then Month[2]=29
for j<-1 to month-1
jianday=jianday+Month[j]
jianday=jianday+day-1
if jianday%5<3
then output “打鱼”
else
output “晒网”
代码:
#include <iostream>
using namespace std;
int Isrunyear(int a);
int main()
{
int year,month,day;
int i,j,jianday=0;
cin>>year>>month>>day;
for(i=1990;i<year;i++)
{
if(Isrunyear(i))
jianday+=366;
else
jianday+=365;
}
int Month[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
if(Isrunyear(year))
Month[2]=29;
for(j=1;j<month;j++)
{
jianday+=Month[j];
}
jianday+=day-1;
if(jianday%5<3)
cout<<"打鱼"<<endl;
else
cout<<"晒网"<<endl;
return 0;
}
int Isrunyear(int a)
{
if(((a%4==0)&&(a%100!=0))||(a%400==0))
return 1;
else
return 0;
}
标签:int,31,jianday,Month,year,打卡,else From: https://www.cnblogs.com/chukjbgg333/p/17334548.html