cppAcademy
FROM LEARNING TO COMPETING

Beginner.
Your first challenges.

Bulgarian Informatics Group E · 2007–2026

270 independently explained problems: 54 Municipal, 54 Regional, 105 National Olympiad tasks and 57 Autumn Tournament tasks. Start with the easier tasks and work upwards. Difficulty labels are learning estimates, not official ratings; Group E also includes challenging national-level problems. Years follow Arena’s competition-season labels. Source clarifications are noted on affected tasks.
GROUP E2025 · EasyCase analysis

Four Clock Chimes

Autumn Tournament (2025)

Submission name: clock.cpp

Problem summary

A 12-hour clock chimes at quarter hours: 1 strike at :15, 2 at :30, 3 at :45, and 4 plus the hour (1–12) at :00. Four consecutive chimes, fifteen minutes apart, have strike counts a,b,c,d. Determine how many minutes after the first chime a full hour occurred, and the hour and minute of the first chime.

Input

Four integers a,b,c,d describing a correctly working clock.

Output

Three lines: minutes from the first chime to the full hour (possibly zero); first hour (1–12); first minute.

Constraints

Each input is 1,2,3 or an integer from 5 through 16. The sequence is valid.

Worked example

The example is reproduced from the original tournament statement.

Input

3 9 1 2

Output

15
4
45

Solution analysis

  1. Among four successive quarter-hour chimes exactly one is on a full hour. Its strike count is at least 5; subtract 4 to recover that hour H. If its zero-based position is k, it occurs 15k minutes after the first chime.
  2. For k=0, the first display is H:00. Otherwise the first chime is within the preceding hour: H−1, wrapping 1 back to 12. Its minute is 60−15k.
  3. For 3,9,1,2, the full-hour chime is second: k=1 and H=5. The first display is 4:45 and the elapsed time to 5:00 is 15 minutes.

Why it works

A valid group of four consecutive quarter-hour events contains each quarter position once. The unique count above 4 identifies the full-hour event and its hour exactly. Subtracting its known elapsed offset determines the first display, with 12-hour wrapping giving the correct preceding hour.

Complexity: O(1) time and O(1) extra space; all loops have a fixed upper bound.

Watch out. The clock uses hours 1–12, not 0–23. When the first chime is already a full hour, elapsed time is zero.

Commented C++17 solution

An independently written complete program with standard headers.

// Key idea: A valid group of four consecutive quarter-hour events contains each quarter position once.
// The unique count above 4 identifies the full-hour event and its hour exactly.
#include<iostream>
using namespace std;
int main(){
    int strikes[4];
    int position=0;
    for(int i=0;i<4;i++){
        cin>>strikes[i];
        if(strikes[i]>=5){
            position=i;
        }
    }
    int hour=strikes[position]-4;
    int minute=0;
    if(position>0){
        hour=hour==1?12:hour-1;
        minute=60-15*position;
    }
    cout<<15*position<<'\n'<<hour<<'\n'<<minute<<'\n';
}

Source: Arena Olimpiici ↗