爱问知识人 爱问教育 医院库

银行等待时间问题

首页

银行等待时间问题

队列部分:
(1)银行客户平均等待时间
描述
某银行有一个客户办理业务站,在一天内随机地有客户到达,设每位客户的业务办理时间是某个范围内的值。设只有一个窗口,一位业务人员,要求程序模拟统计在一天时间内,所有客户的平均等待时间。模拟数据按客户到达的先后顺序依次由键盘输入,对应每位客户有两个数据,到达时刻和需要办理业务的时间。
Input
第一行:一天内的客户总人数n
第二行:第一个客户的到达时刻和需要办理业务的时间
第三行:第二个客户的到达时刻和需要办理业务的时间
……
第n行:第n - 1个客户的到达时刻和需要办理业务的时间
第n + 1行:第n 个客户的到达时刻和需要办理业务的时间


以下是我编的程序

#include<malloc.h> 
#include<stdio.h> 
#define OK 1
#define ERROR 0
typedef int Status; // Status是函数的类型,其值是函数结果状态代码,如OK等
typedef int QElemType;
#define MAXQSIZE 100 // 最大队列长度(对于循环队列,最大队列长度要减1)

typedef struct
{
   QElemType *base; // 初始化的动态分配存储空间
   int front; // 头指针,若队列不空,指向队列头元素
   int rear; // 尾指针,若队列不空,指向队列尾元素的下一个位置
 }SqQueue;

typedef struct
{
int arrive;
int deal;
}qelem;


Status InitQueue(SqQueue &Q)   
{
// 构造一个空队列Q,该队列预定义大小为MAXQSIZE
   QElemType  *base,front,rear;
    se=(QElemType *)malloc(MAXQSIZE *sizeof(QElemType));
   if (! se)
   return ERROR;
    ont= ar=0;
  return OK;
}
// Status InitQueue(SqQueue *Q)  这两个Q一样吗 
// { /* 构造一个空队列Q */
//   (*Q).base=(QElemType *)malloc(MAXQSIZE*sizeof(QElemType)); 为什么不写100 
//   if(!(*Q).base) /* 存储分配失败 */
//     exit(OVERFLOW);
//   (*Q).front=(*Q).rear=0;
//   return OK;
// }

Status EnQueue(SqQueue &Q,QElemType e)  
{ 
// 插入元素e为Q的新的队尾元素
QElemType  *base,front,rear;
if(( ar+1)%MAXQSIZE== ont) 
   return ERROR;
    se[ ar]=e;
    ar=( ar+1)%MAXQSIZE;
  return OK;
} 

 //Status EnQueue(SqQueue *Q,QElemType e)
// { /* 插入元素e为Q的新的队尾元素 */
//   if((*Q).rear>=MAXQSIZE)
//   { /* 队列满,增加1个存储单元 */
//     (*Q).base=(QElemType *)realloc((*Q).base,((*Q).rear+1)*sizeof(QElemType));
//     if(!(*Q).base) /* 增加单元失败 */
//       return ERROR;
//   }
//   *((*Q).base+(*Q).rear)=e;
//   (*Q).rear++;为什么自加 
//   return OK;
// }
Status DeQueue(SqQueue &Q, QElemType &e) 
{  
// 若队列不空, 则删除Q的队头元素, 用e返回其值, 并返回OK; 否则返回ERROR
//请补全代码//
QElemType  *base,front,rear;
if( ar== ont) 
return ERROR;
e= se[ ont];
 ont=( ont+1)%MAXQSIZE;
return OK;
}
// Status DeQueue(SqQueue *Q,QElemType *e)
// { /* 若队列不空,则删除Q的队头元素,用e返回其值,并返回OK,否则返回ERROR */
//   if((*Q).front==(*Q).rear) /* 队列空 */
//     return ERROR;
//   *e=(*Q).base[(*Q).front];
//   (*Q).front=(*Q).front+1;
//   return OK;
// }


int main()
{
   int n,i,e1,e2,nowtime=0,totaltime=0;float s;
   SqQueue S;
   qelem x;
  
   scanf("%d",&n);
   for(i=0;i<n;i++)
   {
      scanf("%d,%d",& rive,& al);
      EnQueue(S, rive);
      EnQueue(S, al);
   }
      DeQueue(S,e1);
      DeQueue(S,e2);
      nowtime=e1+e2;
   for(i=0;i<n-1;i++)
    {
     DeQueue(S,e1);
     DeQueue(S,e2);
     if (nowtime>e1)
         {
             totaltime=totaltime+nowtime-e1+e2;
             nowtime=nowtime+e2;
         }
     else
        nowtime=e1+e2;
    }
s=(float)totaltime/(float)n;
printf("%.2f",s);
system("PAUSE");
}

编译的出来,但不能运行,麻烦告诉我错哪了

提交回答
好评回答
  • 2012-12-29 14:44:59
      程序已经改好,修改说明都在圆括号里面。
    #include 
    #include  
    #define OK 1
    #define ERROR 0
    #define MAXQSIZE 100 // 最大队列长度(对于循环队列,最大队列长度要减1)
    typedef int Status; // Status是函数的类型,其值是函数结果状态代码,如OK等
    typedef int QElemType;
    typedef struct
    {
    QElemType *base; // 初始化的动态分配存储空间
    int front; // 头指针,若队列不空,指向队列头元素
    int rear; // 尾指针,若队列不空,指向队列尾元素的下一个位置
    }SqQueue;
    typedef struct
    {
    int arrive;
    int deal;
    }qelem;
    Status InitQueue(SqQueue &Q) 
    {
    // 构造一个空队列Q,该队列预定义大小为MAXQSIZE
    // QElemType *base,front,rear;(删除)
     se=(QElemType *)malloc(MAXQSIZE*sizeof(QElemType));
    if(! se)
    return ERROR;
     ont= ar=0;
    return OK;
    }
    // Status InitQueue(SqQueue *Q) 这两个Q一样吗(这里的Q与上面的Q不一样,这里是C表达,上面是C++表达)
    // { /* 构造一个空队列Q */
    // (*Q)。
      base=(QElemType *)malloc(MAXQSIZE*sizeof(QElemType)); 为什么不写100(为了更加通用) // if(!(*Q)。base) /* 存储分配失败 */ // exit(OVERFLOW); // (*Q)。
      front=(*Q)。rear=0; // return OK; // } Status EnQueue(SqQueue &Q,QElemType e) { // 插入元素e为Q的新的队尾元素 //QElemType *base,front,rear;(删除) if(( ar+1)%MAXQSIZE== ont) return ERROR; se[ ar]=e; ar=( ar+1)%MAXQSIZE; return OK; } //Status EnQueue(SqQueue *Q,QElemType e) // { /* 插入元素e为Q的新的队尾元素 */ // if((*Q)。
      rear>=MAXQSIZE) // { /* 队列满,增加1个存储单元 */(建议一次多增加几个数组元素) // (*Q)。base=(QElemType *)realloc((*Q)。base,((*Q)。rear+1)*sizeof(QElemType)); // if(!(*Q)。
      base) /* 增加单元失败 */ // return ERROR; // } // *((*Q)。base+(*Q)。rear)=e; // (*Q)。rear++;为什么自加(队尾位置变化了) // return OK; // } Status DeQueue(SqQueue &Q, QElemType &e) { // 若队列不空, 则删除Q的队头元素, 用e返回其值, 并返回OK; 否则返回ERROR //请补全代码// //QElemType *base,front,rear;(删除) if( ar== ont) return ERROR; e= se[ ont]; ont=( ont+1)%MAXQSIZE; return OK; } // Status DeQueue(SqQueue *Q,QElemType *e) // { /* 若队列不空,则删除Q的队头元素,用e返回其值,并返回OK,否则返回ERROR */ // if((*Q)。
      front==(*Q)。rear) /* 队列空 */ // return ERROR; // *e=(*Q)。base[(*Q)。front]; // (*Q)。front=(*Q)。front+1; // return OK; // } void main() { int n,i,e1,e2,nowtime=0,totaltime=0; float s; SqQueue S;//(建议一个程序中不要同时用大S和小s作变量名,看上去容易混淆) qelem x; InitQueue(S);//(漏了队列初始化调用) scanf("%d",&n); for(i=0;ie1) { totaltime=totaltime+nowtime-e1;//(去掉+e2,某人的等待时间不包括自己的办理时间); nowtime=nowtime+e2; } else nowtime=e1+e2; } s=(float)totaltime/(float)n; printf("%。
      2f",s); //system("PAUSE"); }。

    大***

    2012-12-29 14:44:59

  • C/C++ 相关知识

  • 电脑网络技术
  • 电脑网络

相关推荐

正在加载...
最新资料 推荐信息 热门专题 热点推荐
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200

热点检索

  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 176-195
返回
顶部
帮助 意见
反馈

确定举报此问题

举报原因(必选):