Some questions of NXUOJ C language final examination

1,China No 1!

Problem description

On April 29, the Long March 5 (CZ-5) B yao-2 carrier rocket (nickname: pang-5) carrying out the mission of the "Tianhe" core module of China's space station was ignited and launched at China's Wenchang space launch site.

I believe that as long as you watch the live broadcast, you will be moved by our strong motherland and just want to play China No 1!
Then please use the program to output China No 1!

Problem solution

python reference solution

'''
Author: Gu Jiakai
Date: 2021-07-02 21:08:32
LastEditTime: 2021-07-02 21:56:51
LastEditors: Gu Jiakai
Description: 
FilePath: \nxuoj\China No 1!.py
'''
print("China No 1!")

C + + reference solution

/*** 
 * @Author: Gu Jiakai
 * @Date: 2021-07-02 21:58:15
 * @LastEditTime: 2021-07-02 22:07:32
 * @LastEditors: Gu Jiakai
 * @Description: 
 * @FilePath: \nxuoj\ChinaNo1.cpp
 */

#include <cstdio>

using namespace std;

int main()
{
    printf("%s\n","China No 1!");
}

2. Taiwan Province of the people's Republic of China!

Title Description

In the process of pangwu putting "Tianhe" into orbit, Taiwan province appeared on the telemetry map.

In a few minutes, pangwu put the Tianhe core module into the scheduled orbit. However, we know that when it ignites, the speed is O, which can be used to model a uniformly accelerated motion model.
Our problem is that if we give you a and T and know to=O, So=O, V= O. Please find the displacement st at any t time under the above model.

Input form

The input format is one line, with two integers separated by spaces, indicating o < = A and T < = 2000 respectively.

Output form

The output format is one line, with only one integer, st. If there are decimals, round to the nearest whole.

sample input

1 2

sample output

2

Problem solution

python reference solution

'''
Author: Gu Jiakai
Date: 2021-07-02 22:56:07
LastEditTime: 2021-07-02 23:00:30
LastEditors: Gu Jiakai
Description: 
FilePath: \nxuoj\Taiwan Province of the people's Republic of China!.py
'''

# here put the import lib
a,t=input().split()
print(int(0.5*int(a)*int(t)*int(t)))

C + + reference solution

/*** 
 * @Author: Gu Jiakai
 * @Date: 2021-07-02 23:02:04
 * @LastEditTime: 2021-07-02 23:04:39
 * @LastEditors: Gu Jiakai
 * @Description: 
 * @FilePath: \nxuoj\Taiwan Province of the people's Republic of China cpp
 */

#include <cstdio>

int a,t;
int st;

int main()
{
    scanf("%d%d",&a,&t);
    st=0.5*a*t*t;
    printf("%d",st);
}

3. Long March, our journey is the sea of stars!

Title Description

Long march series launch vehicles are space launch vehicles developed by China. The Long March launch vehicle started in the 1960s. On April 24, 1970, the "Long March 1" launch vehicle successfully launched the "Dongfanghong 1" satellite for the first time. The long march rocket has 4 generations and 19 types of retired and active rockets.

Of course, the future is bright and the road is tortuous. As of June 23, 2021, China's long march series launch vehicles have launched 375 times, of which 17 have failed. However, it also reminds Chinese astronauts to constantly sum up experiences and lessons. So far, the total launch success rate of long march series launch vehicles is still the highest in the world.
We agree to use 1 for each successful launch and - 1 for launch failure. Now we need to count the success rate of ten consecutive launches.

Input form

The input format line is first a number n, and the next N numbers are separated by spaces

Output form

The output format is a number, which is the success rate of these n launches (should be less than or equal to 1), with 3 decimal places reserved.

sample input

10
1 1 1 -1 -1 -1 1 1 1 1

sample output

0.700

Problem solution

python reference solution

'''
Author: Gu Jiakai
Date: 2021-07-04 11:19:43
LastEditTime: 2021-07-04 11:32:07
LastEditors: Gu Jiakai
Description: 
FilePath: \nxuoj\Long March, our journey is the sea of stars!.py
'''
n=eval(input())
sucNum=0
eleSet=input().split()
for ele in eleSet:
    if ele=='1':
        sucNum+=1

print("{:.3f}".format(sucNum/n))

C + + reference solution

/*
 * @Author: Gu Jiakai
 * @Date: 2021-07-04 11:34:49
 * @LastEditTime: 2021-07-04 11:38:22
 * @LastEditors: Gu Jiakai
 * @Description: 
 * @FilePath: \nxuoj\Long March, our journey is the sea of stars CPP
 */
#include <cstdio>

int n,t;

int main()
{
    int sucNum=0;

    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&t);
        if(t==1)
            sucNum+=1;
    }

    printf("%.3f",sucNum*1.0/n);
}

5. Eat out in space

Title Description

On May 29, 2021, tianzhou-2 was launched from Wenchang space launch site in Hainan under the support of the long march-7 yao-3 carrier rocket, and the first "space express" of China's space station began to send parts. The food needed by astronauts in space needs to be transported to the space station in advance by spacecraft. The most important thing in the express is the astronaut's food.

We will pack a certain amount of food as an express. Now there are N packaged space food in the warehouse. Due to the launch of a flight
The ship is not easy. For the next M launch operations, we hope to choose the smallest package for each launch operation
Food.

Input form

The first line contains two integers N, m; In the following N (N < = 500000) lines, each line has a natural number, and the number in line i represents the weight of the food packaged in the smallest i; The following M (m < = 10000) lines, each with a natural number, respectively represent the food required by astronauts in each launch operation. The data ensure that the food must be sufficient, that is, there will be no food requirements that exceed the maximum weight of packaged food.

Output form

Line M, a number in each line, represents the weight of the food selected in this action. Don't consider the food left over from the last flight.

sample input

3 3
2
4
6
1
2
5

sample output

2
2
6

Problem solution

python reference solution

'''
Author: Gu Jiakai
Date: 2021-07-04 12:08:43
LastEditTime: 2021-07-04 12:21:37
LastEditors: Gu Jiakai
Description: 
FilePath: \nxuoj\Eat out in space.py
'''
n,m=input().split()
a=[]
b=[]
for i in range(int(n)):
    ele=input()
    a.append(ele)

for j in range(int(m)):
    mem=input()
    b.append(mem)

for i in b:
    for j in a:
        if j>=i:
            print(j)
            break

C + + reference solution

/*** 
 * @Author: Gu Jiakai
 * @Date: 2021-07-04 12:23:51
 * @LastEditTime: 2021-07-04 12:28:23
 * @LastEditors: Gu Jiakai
 * @Description: 
 * @FilePath: \nxuoj\Go out in space cpp
 */
#include <cstdio>

int n,m;
int a[500001],b[10001];

int main()
{
    scanf("%d%d",&n,&m);
    for(int i=0;i<n;i++)
        scanf("%d",&a[i]);
    for(int j=0;j<m;j++)
        scanf("%d",&b[j]);
    
    for(int i=0;i<m;i++)
    {
        for(int j=0;j<n;j++)
        {
            if(a[j]>=b[i])
            {
                printf("%d\n",a[i]);
                break;
            }
        }
    }

    return 0;
}

8. Backup

Title Description

Shenzhou 12 spacecraft docked with the rocket as a launch ship. When the launch tower was on standby for launch, Shenzhou 13 spacecraft served as a ground standby rescue spacecraft for this mission to complete the preparation before propellant filling,

When the plant is in place, follow-up launch procedures can be started at any time. Once the situation requiring rescue occurs in orbit, the rescue procedure can be started at any time, and the astronauts can be launched into orbit in a short time to return to the ground.

This is called backup. In our daily study and work, it is a common and effective disposal plan to back up our written data.
Now we need to back up two copies of data, both of which are strings. In order to save trouble, we want to back up the two copies of data together. The content of the backup data is "B string 1 + string 2 + ····························"

Input form

Enter the first line n and the next n lines. The length of each line is no more than 4O characters, which may include English characters, numbers, punctuation marks, etc.

Output form

The output is one line, that is, the backed up data

sample input

3
CHINA
No
1

sample output

B_CHINA+No+1

Problem solution

python reference solution

'''
Author: Gu Jiakai
Date: 2021-07-04 12:33:39
LastEditTime: 2021-07-04 12:43:16
LastEditors: Gu Jiakai
Description: 
FilePath: \nxuoj\backups.py
'''
n=eval(input())
back_up_Copy='B_'
for i in range(n):
    if i==0:
        ele=input()
        back_up_Copy+=ele
    else:
        ele=input()
        back_up_Copy+='+'+ele

print(back_up_Copy)

C + + reference solution

/*** 
 * @Author: Gu Jiakai
 * @Date: 2021-07-04 12:45:05
 * @LastEditTime: 2021-07-04 13:02:21
 * @LastEditors: Gu Jiakai
 * @Description: 
 * @FilePath: \nxuoj\Backup cpp
 */
#include <iostream>
#include <string>
#include <cstring>

using namespace std;

int n;
string a;
string back_up_copy="B_";

int main()
{
    int count=0;
    
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a;
        if(count==0)
        {
            back_up_copy.append(a);
            count++;
        }
        else
            back_up_copy.append('+'+a);
    } 

    cout<<back_up_copy<<endl;
    return 0;
}

Added by HaZaRd420 on Sat, 22 Jan 2022 07:14:53 +0200