用程式簡單模擬乙個單佇列多視窗的排隊模式:
設某銀行有乙個固定能容納n個顧客的等候區,顧客想進銀行,若等候區有空則可進,否則被拒絕進入。
每當銀行櫃員叫號時,等候區中最先進入的顧客離開等候區前往櫃檯辦理業務,若叫號時等候區無人,則此次叫號作廢。
第一行輸入乙個不大於20的正整數n
,表示銀行等候區能容納的人數,
接下來用若干行表示依時間順序先後發生的「顧客想進銀行
」或「叫號
」事件,格式分別是:
最後一行是乙個#符號,表示輸入結束。
注意:對於輸入的每個事件,按同樣順序在一行內輸出事件的結果,格式分別是:
3
in 101
in 102
in 103
in 104
calling
in 105
calling
calling
calling
calling
#
101 joined. total:
1102 joined. total:
2103 joined. total:
3104 rejected.
101 called. total:
2105 joined. total:
3102 called. total:
2103 called. total:
1105 called. total:
0no one!
這題考察的是基本列隊的操作,我用的是的是迴圈陣列的方式操作,比較容易理解,我沒在時間內寫完所以pta不知道能不能通過,我只通過了樣例,要是發現有錯誤還望指點一下!
#include
#include
#include
#define max 21
typedef
int elementtype;
typedef
int position;
typedef
struct qnode *ptrtoqnode;
struct qnode
;typedef ptrtoqnode queue;
queue createqueue
(int x)
void
inqueue
(queue q,elementtype s)
q->id[q->rear]
= s;
q->rear =
(q->rear +1)
% q->max;
printf
("%d joined. total:%d\n"
,s,(q->rear - q->head + q->max)
% q->max);}
void
outqueue
(queue q)
int a;
a = q->id[q->head]
;//儲存被call的id
q->head =
(q->head +1)
% q->max;
//頭往前移
int length;
length =
(q->rear - q->head + q->max)
% q->max;
printf
("%d called. total:%d\n"
,a,length);}
intmain()
if(!strcmp
("calling"
,n))
outqueue
(q);if(
!strcmp
("#"
,n))
return0;
}}
C語言銀行業務佇列簡單模擬
設某銀行有a b兩個業務視窗,且處理業務的速度不一樣,其中a視窗處理速度是b視窗的2倍 即當a視窗每處理完2個顧客時,b視窗處理完1個顧客。給定到達銀行的顧客序列,請按業務完成的順序輸出顧客序列。假定不考慮顧客先後到達的時間間隔,並且當不同視窗同時處理完2個顧客時,a視窗顧客優先輸出。輸入格式 輸入...
佇列的模擬實現 c語言
test.c define crt secure no warnings 1 include queues.h intmain queues.c include queues.h include include include include include typedef struct mycir...
C語言單鏈表簡單理解
出於很多剛學習鍊錶的很多小夥伴在學習鍊錶的時候有很多困惑,我在此特地的出一篇部落格,幫助我的朋友們。有寫的不好的地方,大佬請勿略這篇內容 鍊錶裡面的插入資料還是很有講究的 1 頭插法 插入資料 123 4567 89實際輸出 987 6543 212 尾插法 插入資料 123 4567 89實際輸出...