China Electronics Society May 2023 Youth Software Programming C++ Level Examination Paper Level 1 Real Questions (Including Answers)

1. Output the second integer

Input three integers and output the second input integer.
Time limit: 1000
Memory limit: 65536

The input
is a single line of three integers separated by a space. Integers are 32-bit signed integers.

The output
has only one line, one integer, which is the second integer input.

Sample input
123 456 789

Sample output
456

Reference answer:

#include <bits/stdc++.h>
using namespace std;
long long a,b,c;
int main() {
    
    
  cin>>a>>b>>c;
  cout<<b;
  return 0;
}
  1. Evaluate the expression.
    Given the values ​​of the integers x, y, calculate the value of 3 x+2 y.
    Time limit: 3000
    Memory limit: 65536

The input
line contains 2 integers x and y, separated by spaces. The data ensures that the final calculation result is still within the range of integer representation.

Output
Output the results according to the requirements of the question

Sample input
2 3

Sample output
12

Reference answer:

#include <bits/stdc++.h>
using namespace std;
long long x,y;
int main() {
    
    
  cin>>x>>y;
  cout<<x*3+2*y;
  return 0;
}
  1. Judgment of capital letters
    Enter a character and judge whether it is an English capital letter, that is, whether it is one of AZ.
    Time limit: 1000
    Memory limit: 65536

Enter
one character.

Output
If it is English capital letters, output YES, otherwise output NO.

Sample input
K

Sample output
YES

Reference answer:

#include <bits/stdc++.h>
using namespace std;
char a;
int main() {
    
    
  cin>>a;
  if(a>='A' && a<='Z')
      cout<<"YES";
  else cout<<"NO";
      return 0;
}

4. Accumulation of numbers that meet the conditions

There are n integers, and the numbers with k single digits are accumulated and summed.
Time limit: 1000
Memory limit: 65536

Input
the first line of two integers n and k, separated by spaces. (0 < n < 1000, 0 ≤ k ≤ 9) The second line contains n non-negative integers, separated by spaces, each number is not greater than 100000.

Output
Output the cumulative sum that meets the requirements of the question.

Sample input
10 7
2 5 7 17 11 18 4 27 1 7

Sample output
58

Reference answer:

#include <bits/stdc++.h>
using namespace std;
long long n,k,c,f;
int main() {
    
    
  cin>>n>>k;
  while(n){
    
    
      n--;
      cin>>c;
      if(c%10==k)
      f+=c;
  }
  cout<<f;
  return 0;
}

5. Gold coins

The king paid gold coins as wages to loyal knights. On the first day, the knight received one gold coin; for the next two days (the second and third days), he received two gold coins every day; for the next three days (the fourth, fifth, and sixth days), he received three gold coins every day. gold coins; in the next four days (seventh, eighth, ninth, and tenth days), four gold coins will be received every day... This wage payment model will continue like this: after receiving N gold coins every day for N consecutive days, The knight will receive N+1 gold coins every day for the next N+1 consecutive days (N is any positive integer).
You need to write a program that determines how many gold coins the knight earned in a given number of days starting from the first day.
Time limit: 10000
Memory limit: 65536

Enter
an integer (range 1 to 10000) representing the number of days.

Output
The number of gold coins obtained by the knight.

Sample input
6

Sample output
14

Reference answer:

#include<bits/stdc++.h>
using namespace std;
int main()
{
    
    
    int n;
    cin >> n;
    int h=0;
    int l = 1 , i , sum = 0;
    for( i=1;i<=n;i+=l)
    {
    
    
        sum+=l*(i-h);
        l++;
        h=i;
    }
    if(i!=n)
    {
    
    
        sum+=(n-h)*l;
    }
    cout<<sum;
}

Guess you like

Origin blog.csdn.net/m0_46227121/article/details/131212860