标题:cost怎么没起作用呢
只看楼主
xy2bl
Rank: 1
等 级:新手上路
帖 子:61
专家分:2
注 册:2010-12-2
结帖率:100%
已结贴  问题点数:20 回复次数:6 
cost怎么没起作用呢
#define OVERFLOW -2
#define OK 1
#define ERROR 0
#define STACK_INIT_SIZE 1
typedef int status ;
#include<stdio.h>
#include<malloc.h>
#include<stdlib.h>
#include<conio.h>
typedef struct
{int car_num;
int time;
}car_info;
typedef struct
{
car_info *base;
car_info *top;
status stacksize;
}sqstack;
void Initstack(sqstack *s)
{
s->base=(car_info *)malloc(STACK_INIT_SIZE*sizeof(car_info));
if(!s->base) exit(OVERFLOW);
s->top=s->base;
s->stacksize=0;
}
void push(sqstack *s,car_info e)
{
*s->top++=e;
s->stacksize++;
}
car_info pop(sqstack *s)
{car_info e;
if(s->top==s->base)  
{printf("停车场内没有该车辆!\n");
exit(0) ;}
e=*--s->top;
s->stacksize--;
return e;
}
typedef struct Qnode
{
int car_num;
int time;
struct Qnode *next;
}QNode,*QueuePtr;
typedef struct
{
QueuePtr front;
QueuePtr rear;
int lenth;
}LinkQueue;
status InitQueue(LinkQueue *Q)
{
Q->front=Q->rear=(QueuePtr)malloc(sizeof(QNode));
if(!Q->front)exit(OVERFLOW);
Q->front->next=NULL;
Q->lenth=0;
return OK;
}

void EnQueue(LinkQueue *Q,car_info *a )
{  
QueuePtr p;
p=(QueuePtr)malloc(sizeof(QNode));
if(!p)exit(OVERFLOW);
p->car_num=a->car_num;
p->time=a->time;
p->next=NULL;
Q->rear->next=p;
Q->rear=p;
Q->lenth++;

}
QueuePtr DeQueue(LinkQueue *Q)
{ QueuePtr p,e,s={0};
if(Q->front==Q->rear)
{printf("便道上没有车辆!\n"); return s;}
p=Q->front->next;
e=p;
Q->front->next=p->next;
Q->lenth--;
if(Q->rear==p)Q->front=Q->rear;
//free(p);
return e;
  
}
void arrive(sqstack *s,LinkQueue *p,car_info a,int n)
{


if(s->stacksize<n)
{

push(s,a);
printf("\n车牌号为%d的车辆进入停车场%d号车道\n",a.car_num,s->stacksize);
}
else  
{
EnQueue(p,&a);
printf("\n停车场已满,车牌号为%d的车辆停在便道的%d号位置\n",a.car_num,p->lenth);
}
}
void leave(sqstack *tcc,sqstack *dcc,LinkQueue *p,car_info a,float pay)
{
car_info x,ss;
QueuePtr b;
int find=1,arrivetime=0;
float cost=0.0;
while(find)
{

ss=pop(tcc);
push(dcc,ss);
if(ss.car_num==a.car_num)
{
find=0;
cost=(a.time-ss.time)*pay;
arrivetime=ss.time;
}
}
pop(dcc); //把临时堆栈的第一辆车(要离开的)去掉;
while(dcc->stacksize)
{
x=pop(dcc);
push(tcc,x);
}
if(tcc->stacksize<2&&p->lenth!=0)
{
b=DeQueue(p);
x.car_num=b->car_num;
x.time=b->time;
push(tcc,x);
printf("车牌号为%d的车辆由便道进入停车场%d号车道\n",x.car_num,tcc->stacksize);
}
printf("\n**********************************************\n");
printf("|车牌号码|进站时刻|出站时刻|停留时间|停车费用|\n");
printf("|%-6d |%-6d |%-6d |%-6d |%-6.2f |\n",a.car_num,arrivetime,a.time,a.time-arrivetime,cost);
printf("**********************************************\n");
}

void main()
{sqstack tcc,dcc;
LinkQueue p;
car_info a;
int sum=1000,n;
float pay;
char sign;
printf("\n|************************停车场管理**************************|\n");
printf("|******A/a:车辆到达*******D/d:车辆离开******E/e:推出系统*****|\n\n");

Initstack(&tcc);
Initstack(&dcc);
InitQueue(&p);
printf("请先输入停车场的车位总数,收费标准(元/小时):");
scanf("%d%f",&n,&pay);
getchar();
printf("\n请输入A/D/E,车牌号,时刻:");
scanf("%c%d%d",&sign,&a.car_num,&a.time);
getchar();
while(sum)
{
switch(sign)
{
case 'a':
case 'A':arrive(&tcc,&p,a,n);break;
case 'D':
case 'd':leave(&tcc,&dcc,&p,a,pay);break;
case 'e':
case 'E':exit(OVERFLOW);break;
}
printf("\n请输入A/D/E,车牌号,时刻:");
scanf("%c%d%d",&sign,&a.car_num,&a.time);
getchar();
sum--;
}
getch();
}
cost怎么没起作用呢
搜索更多相关主题的帖子: include status 
2010-12-31 01:28
xy2bl
Rank: 1
等 级:新手上路
帖 子:61
专家分:2
注 册:2010-12-2
得分:0 
求助
2010-12-31 01:30
xy2bl
Rank: 1
等 级:新手上路
帖 子:61
专家分:2
注 册:2010-12-2
得分:0 
求助
2010-12-31 10:43
诸葛修勤
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:11
帖 子:549
专家分:1955
注 册:2010-10-28
得分:10 
帮顶上去

2010-12-31 17:45
寒风中的细雨
Rank: 17Rank: 17Rank: 17Rank: 17Rank: 17
等 级:贵宾
威 望:66
帖 子:1710
专家分:8645
注 册:2009-9-15
得分:10 
主函数中
把scanf("%d%f",&n,&pay);
改成scanf("%f%d", &pay, &n);
2010-12-31 21:14
xy2bl
Rank: 1
等 级:新手上路
帖 子:61
专家分:2
注 册:2010-12-2
得分:0 
貌似还是很难啊
2011-01-01 20:27
xy2bl
Rank: 1
等 级:新手上路
帖 子:61
专家分:2
注 册:2010-12-2
得分:0 
版主,我拜你为师,帮帮徒儿吧
2011-01-01 20:35



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-330325-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.232729 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved