| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 636 人关注过本帖
标题:大侠帮帮忙啊!小弟遇到变成麻烦了!
只看楼主 加入收藏
lgxlee
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2007-11-29
收藏
 问题点数:0 回复次数:2 
大侠帮帮忙啊!小弟遇到变成麻烦了!
#include<stdio.h>
#include<stdlib.h>
#define MaxSize 3      //存储空间初始分配量即停车场内的容量
#define PRICE 2                  //每单位时间的停车费
#define NULL 0

typedef struct
{
    char dl;                     //到达、离去标志
    int num;                     //汽车车牌号码
    int time;                    //到达或离去时刻
}car;                            //数据类型
typedef struct
{                           
    car a[MaxSize];
    car top; //栈顶指针
    int count;
}SqStack;
SqStack Park,TempPark;

typedef struct QNode
{
    int data;                                      
    car b[MaxSize];
    struct QNode *next;
}QNode,*QueuePtr;
typedef struct
{
    QueuePtr front;               //队头指针
    QueuePtr rear;                //队尾指针
}Queue;
Queue Q;

int MONEY,n;
void InitStack(SqStack *S)
{
    S->count=NULL;//构造一个空栈
}//InitStack
int Push(SqStack *S,car e[])
{
    if(S->count==MaxSize-1) return false;
    else
    {
    S->count++;
    S->a->dl=e->dl;
    S->a->num=e->num;
    S->a->time=e->time;
    }
    return true;
}//Push
int GetTop(SqStack *S,car &e)
{
                                  //若栈不空,则用e返回S的栈顶元素,
                                  //并返回OK,否则返回ERROR
    if(S->count==0) return false;
    e.dl=S->a[S->count].dl;
    e.num=S->a[S->count].num;
    e.time=S->a[S->count].time;
    return true;
}//GetTop
int Pop(SqStack &S,car &e)
{
                                  //若栈不空,则删除S的栈顶元素,用e返回其值
    if(S.count==0)return false;
    e.dl=S.a[S.count--].dl;                   //栈顶元素送e且指针前移
    e.num=S.a[S.count--].num;
    e.time=S.a[S.count--].time;
    return true;
}//Pop
//查找栈中是否有与e牌号相同的汽车,若有,则返回true,否则返回false
void check(SqStack *S,car e)
{
          SqStack *temp;
          int temp->count;
              temp->count=0;         //从栈底开始检查
          while((temp->count!=S->count)&&(temp->a.num!=e.num))(temp->count)++;
            return   temp->count;                       //若未检查完且尚未检查到有相同的车辆
                                     //则temp++
          if(temp->count==S->count)return false; //若已检查完还为检查到,则返回false
          else
              return true;
}

//有关队列(停车场外的便道)的一些操作

void InitQueue(Queue &Q)
{             //构造一个空队列Q
    Q.front=Q.rear=(QueuePtr)malloc(sizeof(QueuePtr));
    if((QueuePtr)malloc(sizeof(QueuePtr)==0)return false;         //存储分配失败
    Q.front=Q.rear=0;
}

void DestroyQueue(Queue &Q)
{
    while(Q.front){
        Q.rear=Q.front ->next;
        free(Q.front);
        Q.front =Q.rear ;
    }
    return true;
}


void EnQueue(Queue &Q,car e)
{
                                      //插入元素e为新的队尾元素
    QueuePtr p;
    p=(QueuePtr)malloc(sizeof(QueuePtr));
    if(!p)return false;               //存储分配失败
    p->data=e.num;
    p->next=NULL;                     //指针p的存储
    Q.rear->next=p;                   //p插入到队尾
    Q.rear=p;                         //队尾指针后移
    return true;
}
void DeQueue(Queue &Q,car &e)
{
                                     //若列队不空,则删除Q的队头元素,
                                     //用e返回其值并返回OK,否则返回ERROR
    if(Q.front==Q.rear)return false;
    QueuePtr p;
    p=Q.front->next;                 //p指向队头指针的下一个存储空间
    e.num=p->data;                   //队头元素送e
    Q.front->next=p->next;           //Q指针后移
    if(Q.rear==p)Q.rear=Q.front;     //保存队尾指针
    free(p);
    return true;
}
//其它函数

//初始化
void Initialization()
{
        
       printf("************************************\n\n");
       printf("* 停车场管理模拟*\n\n");
       printf("*************************************\n\n");
       printf("请确认停车场的容量:%d\n",MaxSize);  
       InitStack(Park);
       InitStack(TempPark);
       InitQueue(Q);
       printf("To input the cars' information here:");
}

//对车辆信息进行处理的程序
void process(car b)
{
     car e,tem;
     QNode *q;
     if(b.dl=='A')   {                 //有车辆到达     
                if(Park.top<Park.stacksize)
                                       //若栈未满
                Push(Park,b);          //则入栈
                else EnQueue(Q,b);     //否则插入便道上的车为新的队列元素
                printf("第%d号车停在%d号便道上",b.num,Q.front->data);
          }
          else
          {
                if(!check(Park,b))     //未检查到
                 printf("输入错误,停车场中没有这辆车请重新输入!\n");
                 if(b.num==(Park.top-1)->num) Pop(Park,e);
                                        //如果是最后一辆车则使其出栈
                 else
                 {
                          
                     do{
                               Pop(Park,tem);
                               Push(TempPark,tem);      
                          }while(b.num!=(Park.top-1)-> num); //被检测到但不符合条件的出栈
                                                             //且进到过道栈中
                          Pop(Park,e);                       //符合条件的车出栈并将其值给e
                          do   {
                                  Pop(TempPark,tem);
                                  Push(Park,tem);            //在过道上的车进栈
                          }while(TempPark.top!=TempPark.base);
                  }
                  MONEY=(b.time-e.time)*PRICE;
                  printf("第%d号车的费用是:%d\n",b.num,MONEY);
          }
          if(Q.front!=Q.rear){
                           DeQueue(Q,tem);                  //过道栈的队头元素出队并将值给tem
                           Push(Park,tem);                  //过道栈的第一辆车进停车场栈
          }
              
          q=Q.front;                                   //
               while(q->next!=NULL)                         //列队非空
               {if(q->b.num!=b.num)
                 q=q->next;
                else
                {  q->next=q->next->next;
                   Q.front->data--;
                  if(q->next==NULL)
                    Q.rear=Q.front;
                  printf("第%d号车离开便道\n",b.num);
                }
}
}
int main()
{
    Initialization();
    car c;
    int n;
    scanf("%c %d %d",&c.dl,&c.num,&c.time);
    if(c.dl!='A'&&c.dl!='D'&&c.dl!='E')
        printf("输入错误,请重新输入!\n");
    scanf("%c %d %d",&c.dl,&c.num,&c.time);
    while(c.dl!='E')
    {
        process(c);
        printf("请输入下一辆车的信息:\n");
        scanf("%c %d %d",&c.dl,&c.num,&c.time);
    }
    printf("程序结束\n");
    return 0;
}

题目是这个!大侠一定救救我啊!
停车场管理

[问题描述]

设停车场是一个可停放n辆车的狭长通道,且只有一个大门可供汽车进出。在停车场内,汽车按到达的先后次序,由北向南依次排列(假设大门在最南端)。若车场内已停满n辆车,则后来的汽车需在门外的便道上等候,当有车开走时,便道上的第一辆车即可开入。当停车场内某辆车要离开时,在它之后进入的车辆必须先退出车场为它让路,待该辆车开出大门后,其它车辆再按原次序返回车场。每辆车离开停车场时,应按其停留时间的长短交费(在便道上停留的时间不收费)。

[设计要求]

(1) 要求以顺序栈模拟停车场,以链队列模拟便道。

(2) 从终端读入汽车到达或离去的数据,每组数据包括三项:①是“到达”还是“离去”;②汽车牌照号码;③“到达”或“离去”的时刻。与每组输入信息相应的输出信息为:如果是到达的车辆,则输出其在停车场中或便道上的位置;如果是离去的车辆,则输出其在停车场中停留的时间和应交的费用。
搜索更多相关主题的帖子: int car define 
2007-11-29 16:37
ROLYPOLYTNT
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2007-11-29
收藏
得分:0 
....
2007-11-29 18:21
l670397306
Rank: 1
等 级:新手上路
帖 子:96
专家分:0
注 册:2007-10-13
收藏
得分:0 

2007-11-29 21:25
快速回复:大侠帮帮忙啊!小弟遇到变成麻烦了!
数据加载中...
 
   



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

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