资源简介
Project 2: Jumping the Queue
The beginning of a winter break near Spring Festival is always the beginning of a peak period of transportation. If you have ever tried to get a train ticket at that time, you must have witnessed the endless queues in front of every ticket box window. If a guy has seen his friend in a queue, then it is very much likely that this lucky guy might go straight to his friend and ask for a favor. This is called "jumping the queue". It is unfair to the rest of the people in the line, but, it is life. Your task is to write a program that simulates such a queue with people jumping in every now and then, assume that, if one in the queue has several friends asking for favors, he would arrange their requests in a queue of his own.
Input Specification:
Your program must read test cases from a file “input.txt”. The input file will contain one or more test cases. Each test case begins with the number of groups n (1<= n <=1000). Then n group descriptions follow, each one consisting of the number of friends belonging to the group and those people's distinct names. A name is a string of up to 4 characters chosen from {A, B, ..., Z, a, b, ..., z}. A group may consist of up to 1000 friends. You may assume that there is no one belong to two different groups.
Finally, a list of commands follows. There are three different kinds of commands:
ENQUEUE X - Mr. or Ms. X goes into the queue
DEQUEUE - the first person gets the ticket and leave the queue
STOP - end of test case
The input will be terminated by a value of 0 for n.
Output Specification:
For each test case, output to a file “output.txt”. First print a line saying "Scenario #k", where k is the number of the test case. Then, for each DEQUEUE command, print the person who just gets a ticket on a single line. Print a blank line between two test cases, but no extra line at the end of output.
Sample Input:
2
3 Ann Bob Joe
3 Zoe Jim Fat
ENQUEUE Ann
ENQUEUE Zoe
ENQUEUE Bob
ENQUEUE Jim
E

代码片段和文件信息
#include
#include
#include
typedef unsigned int Index;
typedef Index Position;
struct HashEntry;
struct HashTbl;
typedef struct HashEntry Cell;
typedef struct HashTbl *HashTable;
Index Hash(const char * keyint Tablesize); /*The hash function*/
void InitializeTable(int TableSize); /*Function to initialize the Hash table*/
void DestroyTable(); /*Function to destroy the Hash table and free the memory*/
Position Find(char * key); /*Find functiong to get the position of KEY*/
void Insert(char * keyint segnumberint FLAG); /*Insert the KEY to Hashtable*/
void Input (char *** Poem int seg int line); /*Read the Poem*/
void Output (char *** Poem int seg int line); /*Output the Poem to an output file*/
struct HashEntry /*The structure of each HashTable element CELL*/
{
char Element[80];/*Used to store the content of each First line or Last line*/
int Head; /*First line TAG of each segment used to store the segment number of each “First line“*/
int Tail; /*Last line TAG of each segment used to store the segment number of each “Last line“*/
};
struct HashTbl
{
int TableSize;
Cell * TheCells;
};
/*******************************Global Variables definition**********************************/
FILE *fp; /*To read a file “input.txt“*/
FILE *fout; /*To output data to the file “output.txt“*/
HashTable H;
int Scenario_number=1; /*variable to record the scenario number Initial value is 1*/
/**************************Functions to operate the Hash table*************************************/
Index Hash(const char * keyint TableSize)
{
unsigned long int HashVal=0;
while(*key!=‘\0‘)
HashVal=(HashVal<<5)+*key++;
return HashVal%TableSize; /*Hash function to return the position of KEY in the Hash table H*/
}
void InitializeTable(int TableSize)
{
int i;
H=malloc( sizeof( struct HashTbl ) ); /*Allocate memory for H*/
if(H==NULL)
printf(“out of space!!“);
H->TableSize=TableSize; /*Initial size*/
H->TheCells=malloc(sizeof( Cell ) * H->TableSize); /*Allocate memory for H->TheCells*/
if(H->TheCells==NULL)
printf( “out of space!!“ );
for(i=0;iTableSize;i++)
{
H->TheCells[i].Element[0]=‘\0‘;
H->TheCells[i].Head=-1; /*Initial value is -1 means it is empty */
H->TheCells[i].Tail=-1; /*Initial value is -1 means it is empty */
}
return;
}
void DestroyTable() /*Destroy the Hash table*/
{
free(H->TheCells); /*Free the memory of H->TheCells*/
free(H); /*Free the memory of H */
return;
}
Position Find(char * key)
{
Position CurrentPos;
int CollisionNum;
CollisionNum=0; /*To record the collision numbers */
CurrentPos=Hash(keyH->TableSize); /*Using Hash function to get the first Position of KEY*/
while( !(H->TheCells[CurrentPos
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 452 2008-10-04 20:38 G06\G06\code\input.txt
文件 6931 2008-10-04 20:25 G06\G06\code\Project2.c
文件 196655 2008-10-04 20:25 G06\G06\code\Project2.exe
文件 496 2008-10-04 20:40 G06\G06\code\Readme.txt
目录 0 2008-10-08 10:04 G06\G06\code
目录 0 2009-03-03 21:43 G06\G06
目录 0 2009-03-03 21:43 G06
----------- --------- ---------- ----- ----
204534 7
- 上一篇:成绩记录簿
- 下一篇:IAR中文版教程 IAR教程
相关资源
- The GNU C Library Reference Manual (1196页)
- C++17 The Complete Guide
- the Art & Science of C电子版PDF+DOC 带目录
- The Design And Evolution Of C++英文版
- c语言实现的模板(list queue stack)
-
Data Structures and Other ob
jects Using C++( - Boost Graph Library:The User Guide and Referen
- Ethernet 帧结构解析程序
- C++ High PerformanceA Boost and optimize the p
- Stratus High Level Synthesis User Guide
- Using the C++ Standard Template Libraries《C+
-
Inside the C++ ob
ject Model中英两个版本 - The Nurbs book (2nd.Edition)
- The C Programming Language中文版和英文版两
- 免费:C++ Primer Plus 6th Edition英文版p
- the c programming language 的答案官方版p
- C++:The Core Language
- The Boost C++ Libraries.pdf
-
Inside_the_C++_ob
ject_Model - c++ 17 the complete guide
- The C++ Programming Language习题答案清晰版
- 基于MFC的Cohen-Sutherland直线裁剪算法
-
《Inside The C++ ob
ject Model》英文pdf - ethercat电机mfc简单连接程序
- The C++ Standard Library中文版
- The Art of Scientific Computing第二版、第三
- C++ Templates The Complete Guide (2nd Editio
- C++编程风格(PDF 英汉对照 The Element
- C++参考大全第四版中文版pdf + 英文p
- C++ Templates The Complete Guide 2nd Edition e
评论
共有 条评论