Analysis of C++ Competition Problems from the 2025 National Youth Information Literacy Contest

1. Time Converter

Problem Description

As we all know, 1 hour = 3600 seconds. Please write a program to create a time converter that takes seconds as input and outputs the corresponding hours, discarding any fractions of an hour. For example, if the input is 3600, it is exactly 1 hour, output 1; if the input is 7206, it exceeds 2 hours but is less than 3 hours, output 2.

Input:

A single line containing an integer representing the number of seconds s.

Output:

A single line containing an integer representing the corresponding number of hours h.

Data Range:

s and h are both positive integers within the int range.

Sample Input 1:

7206

Sample Output 1:

2

Sample Input 2:

3600

Sample Output 2:

1

// Reference Code
#include <iostream>
using namespace std;
int main() {
    int s, h;
    cin >> s;
    h = s / 3600;
    cout << h << endl;
    return 0;
}

Division operation (/): When both the dividend and divisor are integers, it performs integer division, meaning the result is the quotient (discarding the decimal part).

2.Contaminated Reagent

Problem Description

There are four types of chemical reagents in the laboratory, numbered 1, 2, 3, and 4. Only one of the reagents is contaminated, which will cause a dangerous reaction when mixed, while the other three are safe. Researcher A mixed reagents 1 and 2, while researcher B mixed reagents 1 and 3. Given the experimental results of A and B, where 0 represents a dangerous reaction and 1 represents safety, please deduce the type number of the contaminated reagent.

Input:

Two integers (0 or 1) representing the experimental results of A and B, separated by a space.

Output:

An integer (1-4) representing the type number of the contaminated reagent.

Data Range:

The input consists only of 0 and 1.

Sample Input 1:

1 1

Sample Output 1:

4

Sample Input 2:

0 1

Sample Output 2:

2

// Reference Code
#include <iostream>
using namespace std;
int main() {
    int a, b;
    cin >> a >> b;
    for(int x = 1; x <= 4; x++) {
        int res_a = (x == 1 || x == 2) ? 0 : 1;
        int res_b = (x == 1 || x == 3) ? 0 : 1;
        if(res_a == a && res_b == b) {
            cout << x << endl;
            break;
        }
    }
    return 0;
}

According to the original problem, when a=0 and b=0, output 1.

Test this code:

When input a=0, b=0, loop i=1 to 4:

i=1:

res_a: (1==1 || 1==2) → true → a==0 → 0==0 → true

res_b: (1==1 || 1==3) → true → b==0 → 0==0 → true → satisfied, output 1.

i=2:

res_a: (2==1 || 2==2) → true → a==0 → 0==0 → trueres_b: (2==1 || 2==3) → false → b==1 → 0==1 → false → not satisfied.

i=3:

res_a: (3==1 || 3==2) → false → a==1 → 0==1 → false → not satisfied.

i=4:

res_a: false → a==1 → 0==1 → false → not satisfied.

Thus, only i=1 satisfies, output correct.

Input: A=0 (danger), B=0 (danger) → Output: 1

Input: A=0 (danger), B=1 (safe) → Output: 2

Input: A=1 (safe), B=0 (danger) → Output: 3

Input: A=1 (safe), B=1 (safe) → Output: 4

// Reference Code
#include <iostream>
using namespace std;
bool isLeap(int y) {
    return((y % 400 == 0) || (y % 4 == 0 && y % 100 != 0));
}
int main() {
    int year;
    cin >> year;
    while(year > 0) {
        if(isLeap(year)) {
            cout << year << endl;
            return 0;
        }
        year--;
    }
    return 0;
}

Test Cases:

Input Output Description

2020 2020 Current is a leap year

2021 2020 Previous leap year

1900 1896 Not satisfying the 400 condition for century years

2000 2000 Century year satisfying the 400 condition

3. Sensor Data Statistics

Problem Description

Recently, Xiao Ming installed n sensors in an autonomous vehicle project. These sensors collect real-time road environment data. He found that when a certain digit in the sensor data is a multiple of 3, it may correspond to a critical road condition signal, and that digit should be counted as a valid signal. Please write a program to analyze the data from n sensors and calculate the sum of all valid signal digits.

Input:

The first line contains an integer n (1≤n≤1000), representing the number of sensors. The second line contains n integers representing the raw data collected by the sensors (values within the int range of positive integers).

Output:

An integer representing the sum of valid digits in the n sensor data.

Data Range:

1 ≤ n ≤ 1000

Sample Input:

36 42 15

Sample Output:

9

// Reference Code
#include <iostream>
using namespace std;
int main() {
    int n, num;
    cin >> n;
    int sum = 0;
    for(int i = 0; i < n; i++) {
        cin >> num;
        while(num > 0) {
            int x = num % 10;
            if(x % 3 == 0) sum += x;
            num /= 10;
        }
    }
    cout << sum << endl;
    return 0;
}

4. Smart Lighting System

Problem Description

The smart lighting system of the Golden Hall in Vienna adjusts the lighting based on the frequency of musical notes. When the difference in the occurrence of the highest and lowest frequency notes in the piano score is even, the lighting will display a rainbow spectrum; otherwise, the concert hall will maintain basic lighting. Assume maxn represents the occurrence of the highest frequency note, and minn represents the occurrence of the lowest frequency note.

Input:

A single line containing a string of musical notes, consisting only of uppercase letters A, B, C, D, E, F, G, with a length of less than 100.

Output:

Two lines of output.

First line: If the rainbow spectrum is triggered, output “Luminous Harmony”; otherwise, output “Silent Keys”;

Second line: Output the difference maxn – minn.

Data Range:

1 ≤ n ≤ 1000

Sample Input 1:

BABABC

Sample Output 1:

Luminous Harmony

2

Sample Input 2:

ABCDGAAA

Sample Output 2:

Silent Keys

3

Sample Input 3:

AAAAAAAA

Sample Output 3:

Luminous Harmony

0

// Reference Code
#include <iostream>
#include <string>
using namespace std;
int main() {
    string s;
    cin >> s;
    int count[7] = {0};
    for(char c : s) {
        count[c - 'A']++;
    }
    int maxn = 0;
    int minn = 100;
    for(int i = 0; i < 7; i++) {
        if(count[i] > 0) {
            maxn = max(maxn, count[i]);
            minn = min(minn, count[i]);
        }
    }
    if((maxn - minn) % 2 == 0)
        cout << "Luminous Harmony" << endl;
    else
        cout << "Silent Keys" << endl;
    cout << maxn - minn << endl;
    return 0;
}

Analysis of C++ Competition Problems from the 2025 National Youth Information Literacy Contest

Leave a Comment