Hack Athlon 2
Hack Athlon 2
General Instructions:
Rules:
The allowed libraries are stdio.h and stdlib.h (only for malloc, calloc, free).
Your program should be modular. Do not write your entire program in main. Create suitable
functions.
For each function you create, 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 accept input till EOF. You can detect this by checking if scanf returned
-1.
Problem 1
Input: Each instance will have followed by , and a number .
Format:
\n
\n
\n
Goal: Check if there exists a contiguous subarray that has sum . More precisely, check if
there exists such that .
Output:
Remark: Every 3 lines of the input forms one input instance. Process each input instance as it is
received. Stop at EOF.
Problem 2
Input:
Output: Print the values of , , and , each separated by a space. Terminate the line with a
\n .
Example:
Input: 1 5 7 11 \n
Output: 1 2 3 \n
Remark: Every line of the input forms an input instance. Process each input instance as it is received.
Stop at EOF.
Problem 3
Input: followed by a string consisting of characters from the set of
length at most . This is followed by series of "pattern" strings , each of length
at most .
Format:
\n
\n
\n
\n
Goal: For each pattern string given as input, find every occurence of in .
Output: Print the starting position of every occurence in separated by a space. If does
not exist, print . Terminate all output lines with \n
Remark: The first two lines of input define the main string . This does not change for the rest of the
input. The pattern strings are given as input in separate lines. Process each pattern string as it is
received. Stop at EOF.