Skip to content

A4 - CCC Sample Problems

We are going to look at some problems from the Canadian Computing Competition. There is a junior and senior level. We'll focus on the junior. There are five questions in each competition. The first one is easy, the second is moderate, the third is difficult, and the fourth and fifth are very difficult.

Here are some example from the 2025 Junior competition:

Question 1

See Question Here

Answer
n = int(input())
c = int(input())
p = int(input())

capacity = c * p

if n > capacity:
    print("no")
else:
    print("yes")

Question 2

See Question Here

Answer
num_donuts = int(input())  # D
num_events = int(input())  # E

for i in range(num_events):
    event_type = input()
    amount = int(input())

    if event_type == "+":
        num_donuts += amount
    else:
        num_donuts -= amount

print(num_donuts)

Some Things to Notice

Since these are contest problems that are marked by a computer, there are two key differences from the types of assignments you are used to:

  1. Input and output need to match specifications exactly. There is no room for creativity.
  2. Input statements don't include prompts. The user is just expected to know what they need to enter. This is unrealistic (and very bad design) for a real program, but for a contest problem, it allows us to focus just on input and output.

Your Task

First, try questions 1 and 2 from the 2024 junior competition, found here.

Then, give question 3 a try from the 2025 junior competition, found here. Here is some starter code for this one, which just does the easy part (keeping uppercase letters, getting rid of lowercase letters). The rest is quite tough, but later on I will go through a good strategy once many of you have had a chance to give it a try.

n = int(input())

for i in range(n):

    old_code = input()
    new_code = ""

    for char in old_code:

            if char.islower():
                continue

            if char.isupper():
                new_code += char
                continue



    # Here we are at the end of a product code
    print(new_code) 

Marking for This

Completing Questions #1 and #2 will earn Meets Expectations. If you make some non-trivial progress on Question #3 or similar, you can earn higher.