COMP 118, Fall 2024
This test will consist of three parts:
- A timed moodle based test (2 hours). (60%) Link
- A Kattis contest (48 hours).(40%) Python Link, C++ Link
The moodle test
The Moodle link is here: Moodle test
This will be much like the quizzes, only longer. You can decide to take it:
- Thursday Dec 19, 6:30pm-8:30pm.
- Friday Dec 20, 8:30am-11:00am.
You can take it at either time.
The Kattis Contests
There will be 2 Kattis contests. One will be for Python solutions, the other for C++ solutions. There are 7 Python problem, and 5 C++ problems. Some of the problems are the same for both. You must use the correct language for each.
The Kattis contests open 2024-12-14 08:00 EST and close 2024-12-18 08:00 EST.
Below are the links:
Hints:
Runtime Errors (IMPORTANT):
Some Python IDE’s must be using a different version of Python 3, and what works in your IDE (like codeboard) gives you a “Runtime Error” in Kattis. For example, codeboard lets you loop on a line you input without using a split() on it first, Kattis does not.
You should be using https://www.onlinegdb.com/ to test you code to get around this.
Inputing:
Here’s how to read in lines in Python until an empty line is encountered:
- Use a
whileloop to continuously read input lines usinginput(). - Check if the input line is empty (i.e.,
line == ""). - If it’s empty, break out of the loop.
- Otherwise, process the input line.
Here’s an example code snippet:
while True:
line = input().strip() # Read a line and remove any surrounding whitespace
if line == "": # Check if the line is empty
break # Exit the loop if the line is empty
# Process the line here (e.g., print it or store it)
print("You entered:", line)
Explanation:
input()reads a line of text from the user..strip()removes any leading or trailing whitespace.- The loop runs until an empty line (a single Enter key press) is entered.
- When an empty line is detected, the
breakstatement stops the loop.
If Kattis provides input until EOF in a single stream:
for line in iter(input, ""):
line = line.strip() # Process each line directly
print("You entered:", line)
This is compact and works well for problems that involve reading all input until EOF.
Test this locally by entering lines and pressing Ctrl+D (EOF) when done.
Judging Troubles:
For this to work you really need to creat two lists, one for each judging system. Then sort each. Once sorted, you can have a loop to go through the lists counting the matches. Since the lists are sorted, you can have an index for each list of outcomes, and only increament an index if it matches the the result string you are currently counting.
