代码
好吧,她其实没什么参考价值,可读性极差,而且还最麻烦,来寻求参考价值的人可以不用看了
#include<stdio.h>
#include<math.h>
int main(){
int i,j,a,b,c,time[5],bagin[5],direction[5],floor,add=0;
int judt,nowf,add1;
for(i=0;i<5;i++)
scanf("%d %d %d",&time[i],&bagin[i],&direction[i]);
for(i=0;i<5;i++)
for(j=0;j<4;j++){
if(time[i]>time[1]){
a=time[i];
time[i]=time[i+1];
time[i+1]=a;
b=bagin[i];
bagin[i]=bagin[i+1];
bagin[i+1]=b;
c=direction[i];
direction[i]=direction[i+1];
direction[i]=c;
}
else
continue;
}//给他们按请求时间排序
for(i=0;i<5;i++){
if(direction[i]==0)
judt=(bagin[i]-1)+1+(10-bagin[i])+time[i];//judt指乘客到目的地所需时间
else
judt=bagin[i]+1+bagin[i]+time[i];
if(judt>=time[i+1]){//判断中途是否两次请求一同执行
if(direction[i]==0){//对目的地进行分类,相同则继续判断
if((time[i]+bagin[i])>time[i+1])//判断电梯在接受第二次请求时的楼层
nowf=1+time[i+1]-time[i];
else if((time[i]+bagin[i])==time[i])
nowf=bagin[i];
else
nowf=time[i+1]-(time[i]+bagin[i])+bagin[i];
if((10-nowf)>abs(nowf-bagin[i+1])){//判断是否一同完成第二次请求
add+=time[i+1]+abs(nowf-bagin[i+1])+1+(10-bagin[i+1]);
add1=time[i+1]+abs(nowf-bagin[i+1])+1+2*(10-bagin[i+1]);
printf("%d时,停靠在10楼\n%d时,停靠在10楼\n",add1,add1);
i++;
continue;
}
else{
add+=judt;
printf("%d时,停靠在10楼\n",add);
continue;
}
}
else{
if((time[i+1]-time[i]+2)<=bagin[i]){
nowf=time[i+1]-time[i]+1;
if(nowf<=bagin[i+1]){
add+=time[i+1]-time[i]+2*((bagin[i+1]-nowf+1)+bagin[i]-bagin[i+1]+bagin[i]-1);
add1=time[i+1]-time[i]+((bagin[i+1]-nowf+1)+bagin[i]-bagin[i+1]+bagin[i]-1);
i++;
printf("%d时,停靠在1楼\n%d时,停靠在1楼\n",add1,add1);
continue;
}
else{
add+=time[i+1]-time[i]+2*(nowf-bagin[i+1]+bagin[i]-bagin[i+1]+bagin[i]-1);
add1=time[i+1]-time[i]+(nowf-bagin[i+1]+bagin[i]-bagin[i+1]+bagin[i]-1);
i++;
printf("%d时,停靠在1楼\n%d时,停靠在1楼\n",add1,add1);
continue;
}
}
else{
nowf=bagin[i]-(bagin[i+1]-(bagin[i]+time[i]+1));
if(nowf>=bagin[i+1]){
add+=time[i+1]-time[i]+2*(abs(bagin[i+1]-nowf)+bagin[i+1]);
add1=time[i+1]-time[i]+(abs(bagin[i+1]-nowf)+bagin[i+1]);
i++;
printf("%d时,停靠在1楼\n%d时,停靠在1楼\n",add1,add1);
continue;
}
else{
add+=time[i]+bagin[i]+bagin[i];
printf("%d时,停靠在1楼\n",add);
continue;
}
}
}
}
else{
if(direction[i]==0){
judt=(bagin[i]-1)+1+(10-bagin[i])+time[i];
printf("%d时,停靠在10楼\n",judt);
}
else{
judt=bagin[i]+1+bagin[i]+time[i];
printf("%d时,停靠在1楼\n",judt);
}
add+=judt;
}
}
return 0;
}