Hack Athlon 4
Hack Athlon 4
General Instructions:
Rules:
The allowed libraries are stdio.h and stdlib.h (only for malloc, calloc, realloc, free).
Your program should be modular. Do not write your entire program in main. Create suitable
functions.
For each function, leave a short comment above it describing what the function does.
You are not allowed to use variable length arrays (VLA). All dynamic memory allocation must
be on the heap.
Your program should not have memory leaks. Free all heap memory used.
Your program should take input till EOF. You can detect this by checking if scanf returned -1.
Submission: On Autojudge. Limit of 3, 3, and 4 submissions for problems 1,2, and 3 respectively.
Autojudge will not evaluate problem 1.
Problem 1
(20 marks)
Input:
Output:
Termination: Your program should terminate when either the end of inputFile has been reached,
or the input read is EOF.
Assumption: You can assume that will fit inside int on the machine that we will use to run
your program.
Problem 2
(40 marks)
See the attached file for the description of a command provided in "man page" style. Implement
the command in C.
Remark: The command is a simpler version of grep -n . You can play with grep -n and optional
arguments -v and -i to understand exactly what we want you to implement.
Problem 3
(40 marks)
Queues:
A queue is a "first in first out" data structure. Inserting elements is called 'enqueuing'.
Removing/deleting elements from a queue is called 'dequeueing'.
If you enqueue (insert) elements in this order, then when you call dequeue, the
first element removed is . The second element would be and so on.
Input:
E \n
D \n
Goal:
Maintain a queue of elements. Enqueue elements when input starts with "E". Dequeue when
the input line is "D".
Output:
If the input line said "E ", then enqueue (insert) the number into . No output!
If the input line said "D", then dequeue from and print the number that was dequeued.
If a dequeue was requested on an empty queue, print "Empty".
Implementation Rules:
Although in practice, you would create separate header file(s), we require you to put everything
into just one .c file so that our evaluation server can be used.