Complete Collection of Programming Sample Questions for ICMC-C++ Junior Group
Sample Paper 1
1. Check for Uppercase Letters
DescriptionInput a character and determine whether it is an uppercase English letter, i.e., one of A-Z.
InputA single character.
OutputIf it is an uppercase English letter, output YES; otherwise, output NO.
Sample Input
K
Sample Output
YES
2. Reverse Output
DescriptionInput four integers a, b, c, d in sequence, and output them in reverse order, i.e., output d, c, b, a.
InputA line of four integers a, b, c, d, separated by spaces.<span>0 < a,b,c,d < 10⁸</span>
OutputA line of four integers d, c, b, a, separated by a space.
Sample Input
1 2 3 4
Sample Output
4 3 2 1
3. Largest Prime Less Than n
DescriptionFor a given n, find the largest prime number that is less than n.A prime number is a natural number greater than 1 that cannot be formed by multiplying two smaller natural numbers.
InputA single integer n.<span>(2 < n < 10000)</span>
OutputA single integer, which is the required solution.
Sample Input
100
Sample Output
97
4. Input and Output of Numbers
DescriptionInput an integer and a double-precision floating-point number, first output the floating-point number rounded to two decimal places, then output the integer.
InputA line containing two numbers, an integer N (not exceeding the integer range) and a double-precision floating-point number F, separated by a space.
OutputA line containing two numbers, the floating-point number F rounded to two decimal places and the integer N, separated by a space.
Sample Input
100 123.456789
Sample Output
123.46 100
Sample Paper 2
1. Program to Complete the Following Shape
InputNone
OutputNone
Sample InputNone
Sample OutputNone
2. Odd-Even Operation
DescriptionGiven an integer, if it is odd, multiply it by 3 and add 1; if it is even, divide it by 2.
InputA line containing one integer
OutputA line containing the result of the operation
Sample Input 1
4
Sample Output 1
2
Sample Input 2
3
Sample Output 2
10
3. Find Perfect Numbers in Range
DescriptionFind perfect numbers in the range of positive integers from 2 to n.A perfect number is a number that is equal to the sum of its proper divisors, excluding itself, such as<span>6=1+2+3</span>
InputA line containing a single integer n
OutputA line containing the perfect numbers in ascending order, separated by spaces
Sample Input
7
Sample Output
6
4. Maximum Subarray Sum
DescriptionGiven a sequence of length n, select a contiguous non-empty subarray such that the sum of this subarray is maximized.
Input
- The first line contains an integer n
- The second line contains n integers, which are not less than -50
OutputA line containing a single integer representing the value of the maximum subarray sum
Sample Input
7
2 -4 3 -1 2 -4 3
Sample Output
4
Sample Paper 3
1. Program to Complete the Following Shape
InputNone
OutputNone
Sample InputNone
Sample OutputNone
2. Series Summation
DescriptionInput n, calculate <span>s = 1 - 1/2 + 1/3 - 1/4 + 1/5 - 1/6 + ...... + 1/n</span> value.
InputA line containing one integer
OutputA line containing the calculated result, note that the result should be rounded to 9 decimal places
Sample Input
6
Sample Output
0.616666667
3. Simulated Calculator
DescriptionGiven two integers and an operator, output the result as required
Input
- The first line contains two integers representing the numbers to be operated on
- The second line contains an operator
<span>+</span>represents addition<span>-</span>represents subtraction<span>*</span>represents multiplication<span>/</span>represents division, which should retain 3 decimal places- If it is not one of the above symbols, output error
OutputA line containing the result after the operation
Sample Input
7 8
*
Sample Output
56
4. Large Number Addition
DescriptionGiven two integers not exceeding 200 digits for addition
InputTwo lines containing the two numbers to be added
OutputA line containing the result of the operation
Sample Input
1
9999999999999999999999999
Sample Output
10000000000000000000000000
Sample Paper 4
1. Class Average Score
DescriptionA class has n students, and now the scores of all students are obtained. The class teacher wants to request you, a programming expert, to calculate the average score of the class, with the result rounded to one decimal place.
Input
- The first line contains the number of students in the class
- The second line contains n numbers, representing the students’ scores
OutputA line containing the average score
Sample Input
5
80 81 82 83 84
Sample Output
82.0
2. Express Delivery Cost Calculation
DescriptionAssuming that the express delivery charges are calculated as follows: if each item weighs within 1 kilogram (inclusive), it is charged at 13 yuan; for any excess over 1 kilogram, an additional 5 yuan is charged per kilogram. Please program to calculate the final postage (note that the result should be rounded to one decimal place)
InputA line containing one number
OutputA line containing the final postage
Sample Input
1.5
Sample Output
15.5
3. Digit Count
DescriptionInput an integer and output how many digits this number has.
InputA line containing one integer
OutputA line containing the number of digits
Sample Input
123
Sample Output
3
4. Emergency Center
DescriptionThe rescue center receives many distress signals every day. After receiving a distress signal, the center analyzes the signals to find the most urgent rescuer to provide assistance.The distress signal is a string composed of lowercase letters, and the more occurrences of the substring sos (i.e., the more occurrences of the substring sos), the more urgent the rescuer’s situation is.Now, please help the rescue center find the most urgent rescuer. Note that the sos substrings can overlap in the string, for example, <span>sosos</span> counts as 2 sos.
Input
- The first line contains an integer representing the number of rescuers
- Followed by n lines, each containing two strings composed of lowercase letters, separated by a space; the first string represents the rescuer’s name, and the second string represents the distress signal
Output
- The first line is the name of the most urgent rescuer; if there are multiple most urgent rescuers, output their names in the order of input, separated by spaces
- The second line is an integer representing how many sos substrings are contained in the most urgent rescuer’s distress signal
- Note that if a rescuer has no sos substrings, simply output 0
Sample Input 1
2
adam ineedhelpsosineedhelpsos
mark ineedmorehelpsoshelpmesossoshelpme
Sample Output 1
mark
3
Sample Input 2
3
susan sososososososos
jack sosososososos
allen soshelpsosososososososos
Sample Output 2
susan allen
6
Sample Paper 5
1. Leap Year Determination
DescriptionGiven a year, determine whether this year is a leap year.
InputA single integer representing the input year
OutputA line, output yes for a leap year, otherwise output no
Sample Input
2004
Sample Output
no
2. Sort from Largest to Smallest
DescriptionInput n positive integers, sort these n numbers and output them from largest to smallest
Input
- The first line contains an integer representing the number of numbers
- The second line contains n positive integers
OutputA line containing the sorted result from largest to smallest
Sample Input
5
13 12 1 8 7
Sample Output
13 12 8 7 1
3. Absolute Prime
DescriptionIf a natural number is prime, and its digits can be reversed to form another prime number, then it is called an absolute prime. For example, 13Input a number n, program to find all absolute primes between 1 and n.A prime number is a number that cannot be divided by any other number except for 1 and itself.
InputA line containing a single integer n <span>(1 < n < 10000)</span>
OutputA line containing the numbers that meet the requirements
Sample Input
100
Sample Output
2 3 5 7 11 13 17 31 37 71 73 79 97
4. Sum of Edge Elements of a Matrix
DescriptionGiven an n by m matrix, calculate the sum of the edge elements of this matrix
Input
- The first line contains two integers, representing the number of rows n and columns m
- The next n lines contain m data each
OutputA line containing the sum of the edge elements
Sample Input
3 3
3 4 1
3 7 1
2 0 1
Sample Output
15
Sample Paper 6
1. Odd-Even Separation Summation
DescriptionGiven a sequence, program to separately calculate the sum of even and odd numbers in this sequence
Input
- The first line contains the number of elements in the sequence n
- The second line contains n integers
Output
- The first line contains the sum of even numbers
- The second line contains the sum of odd numbers
Sample Input
5
1 2 3 4 5
Sample Output
6
9
2. Four Leaf Rose Number
DescriptionFind all four-digit numbers that are four-leaf rose numbers: a four-digit number whose digits raised to the fourth power sum to the number itself
InputNone
OutputNone
Sample InputNone
Sample OutputNone
3. Goldbach’s Conjecture
DescriptionAny even number greater than 2 can be expressed as the sum of two different prime numbers. Program to find a set of equations that meet the requirements.
InputA line containing an integer representing the input even number
OutputA line containing an equation that meets the requirements: the left addend must be less than the right addend
Sample Input
8
Sample Output
8=3+5
4. Grid Number Selection
DescriptionGiven an n×m grid, each cell contains a number. Now Xiaoming wants to walk from the top left corner to the bottom right corner, and the direction of movement can only be up, down, or right, and he cannot revisit already traversed cells or go out of bounds. Xiaoming will take all the numbers along the way, and we need to find the maximum number he can take.
Input
- The first line contains two integers n, m
- The next n lines contain m numbers
OutputAn integer representing the maximum value
Sample Input 1
3 4
1 -1 3 2
2 -1 4 -1
-2 2 -3 -1
Sample Output 1
9
Sample Input 2
2 5
-1 -1 -3 -2 -7
-2 -1 -4 -1 -2
Sample Output 2
-10
Sample Paper 7
1. Greatest Common Divisor
DescriptionGiven two integers, find the greatest common divisor of these two numbers
InputA line containing two integers
OutputA line containing the greatest common divisor
Sample Input
20 15
Sample Output
5
2. Four-Digit Perfect Square
DescriptionOutput the perfect squares in the form of aabb among four-digit numbersaabb form: the first two digits are the same, and the last two digits are the samePerfect square: a number that can be obtained by squaring a smaller number
InputNone
OutputOutput in ascending order, each number on a new line
Sample InputNone
Sample OutputNone
3. Valid Identifier
DescriptionGiven a string that does not contain whitespace, determine whether it is a valid C language identifierNote: The problem guarantees that the input is not a reserved wordC language identifier requirements:
- Not a reserved word
- Contains only letters, digits, and underscores
- Does not start with a digit
InputA line containing the input string
OutputA line, output yes if valid; otherwise, output no
Sample Input
A123;b
Sample Output
no
4. Selected Number Summation
DescriptionGiven n integers and an integer k, select k integers from n integers to perform addition to obtain a series of sums.Assuming n=4, k=3, the four integers are 3, 7, 12, 19, their sums are<span>3+7+12=22</span><span>3+7+19=29</span><span>7+12+19=38</span><span>3+12+19=34</span>Now, please calculate how many of these sums are prime numbers.
Input
- The first line contains two integers n and k
<span>(1<=n<=20, k<n)</span> - The second line contains n integers
OutputA single integer representing the count of prime sums
Sample Input
4 3
3 7 12 19
Sample Output
1
Sample Paper 8
1. Least Common Multiple
DescriptionGiven two integers, find the least common multiple of these two numbers
InputA line containing two integers
OutputA line containing the least common multiple
Sample Input
20 15
Sample Output
60
2. Five-Pointed Star Number
DescriptionFind all five-digit numbers that meet the following requirements: a five-digit number whose digits raised to the fifth power sum to the number itself
InputNone
OutputOutput in ascending order, each number on a new line
Sample InputNone
Sample OutputNone
3. Base Conversion
DescriptionGiven a positive integer in decimal, convert it to base R.
InputInput samples contain multiple groups of input, indicating multiple groups of input <span>while(cin>>variable)</span>Each group of input contains two integers, one is the decimal number, and the other is the base R <span>(2<=R<=16)</span>
OutputMultiple lines, each line containing the result in base R. For values exceeding 10 in decimal, use hexadecimal representation <span>(10→'A'……)</span>
Sample Input
7 2
23 12
4 3
Sample Output
111
1B
11
4. Calculate Saddle Point
DescriptionGiven a 5×5 matrix, where each row has only one maximum value and each column has one minimum value, find the saddle point. A saddle point is an element that is the maximum in its row and the minimum in its column.
InputFive rows, each containing five data points
OutputA line containing the row, column, and the saddle point value
Sample Input
11 3 5 6 9
12 4 7 8 10
10 5 6 9 11
8 6 4 7 2
15 10 11 20 25
Sample Output
4 1 8
The above is the complete collection of programming questions from the eight sample papers of ICMC-C++. The copyright of the questions belongs to the competition organizer. This compilation is for learning reference only.