排班查询
轮班表如下:
1,2,3,4;
1,5,2,3;
4,5,2,3;
4,1,5,2;
3,1,5,2;
3,4,1,5;
2,4,1,5;
2,3,4,1;
5,3,4,1;
5,2,3,4;
从2006年1月1日起,1,2,3,4,5各班按此轮班表开始轮流上班,10天为一个轮回。(一天只安排四个班上班,每班工作6小时)
请观察出轮班表的排列规律(不要硬编码,即将该轮班表存储起来),计算出任意一天(如:2006年9月18日)的上班次序。
1/
#include
int IsLeap(int year)//判断是否为闰年
{
if(year%4==0&&year%100!=0||year%400==0)
return(1);
return(0);
}
int Get_Week(int y,int m,int d)
{
long nday=0;
int i=2006;
while(i
if(IsLeap(i)==1)
nday=nday+366;
else
nday=nday+365;
i++;
}
i=1;
while(i
switch(i)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:nday=nday+31;break;
case 4:
case 6:
case 9:
case 11:nday=nday+30;break;
case 2:
{
if(IsLeap(y)==1)
nday=nday+29;
else
nday=nday+28;
break;
}
}
i++;
}
nday=nday+d-1;//处理天数
return(nday%10);
}
int main()
{
int data[10][4]={{1,2,3,4},{1,5,2,3},{4,5,2,3},{4,1,5,2},{3,1,5,2}, {3,4,1,5},{2,4,1,5},{1,3,4,1},{5,3,4,1},{5,2,3,4}};
int year,month,day,i,j;
printf("/nPlease input year,month,day:");
scanf("%d%d%d",&year,&month,&day);
i=Get_Week(year,month,day);
for(j=0;j<4;j++)
printf("%d ",data[i][j]);
return(0);
}
2/
#include
#include
using namespace std;
int mm[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
class btime
{
int d;
int m;
int y;
bool rflag;//是润年就为真
public:btime();
btime(int d,int m,int y);
btime(const btime &bt);
void set(int d,int m,int y);
void checkr();
int checkr(int year);
int tdfrom11();//算出距本年元旦 一共经过的日期日期总数
bool operator >(btime b2);
int operator-(btime b2);//日期之间的时间差距
};
inline btime::btime(){d=0;m=0;y=0;}
btime::btime(int d,int m,int y){this->d=d;this->m=m;this->y=y;checkr();}
btime::btime(const btime &bt){d=bt.d;m=bt.m;y=bt.y;checkr();}
inline void btime::set(int d,int m,int y){this->d=d;this->m=m;this->y=y;checkr();}
void btime::checkr()
{
mm[2]=28;
if((y%4==0&&y%100!=0)||y%400==0){ rflag=true; mm[2]=29; }
}
int btime::checkr(int year)
{
int td=365;
if((year%4==0&&year%100!=0)||year%400==0){ td=366;}
return td;
}
int btime::tdfrom11()
{
int td=0;
int i=1;
for(;i
{
td+=mm[i];
}
for(i=1;i <= this->d;i++)
{
td++;
}
return td;
}
bool btime::operator >(btime b2)
{
if(y>b2.y) return true;
if(y
{
if(m>b2.m) return true;
else if(m
{
if(d>b2.d) return true;
else return false;
}
} return false;
}
int btime::operator-(btime b2)
{
int sum=0;
bool flag=false;
if(this->y > b2.y)
{
for(int yi=b2.y;yi
{
sum+=checkr(yi);
}
}
else if(this->y < b2.y)
{
flag=true;
for(int yi=this->y;yi
sum+=checkr(yi);
}
}
else
{
return abs(this->tdfrom11()-b2.tdfrom11());
}
if(flag==false)
{
sum=sum+this->tdfrom11()-b2.tdfrom11();
}
else
{
sum=sum-this->tdfrom11()+b2.tdfrom11();
}
return sum;
}
void getb(int i)
{
int a[10] = {1,1,0,2,2,3,3,4,4,0};
int b[4];
i=i-1;
b[a[i]-1]=1;
b[a[(i+4)%10]-1]=2;
b[a[(i+6)%10]-1]=3;
b[a[(i+8)%10]-1]=4;
b[a[(i+2)%10]-1]=5;
for(int j=0;j<4;j++)
{
cout< }
cout<
int main()
{
int i=0;
btime BaseT(1,1,2006);
int d;
int m;
int y;
do
{
cout<<"请输入你要查询的日期(以年月日为0结束)"<
cout<<"month:";cin>>m;
cout<<"day:";cin>>d;
if(y==0||m==0||d==0)
{
break;
}
btime b2(d,m,y);
if(BaseT > b2)
{
cout<<(BaseT-b2)<
}
else
{
i=(BaseT-b2)%10+1;
}
getb(i);
}while(1);
return 0;
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
