topic One: Passing scores
Description: 10 students after the final exam marking is completed, a teacher needs to draw a pass line, the requirements are as follows:
(1) The passing line is a multiple of 10;
(2) To ensure that at least 60% of the students pass;
(3) If all students are above 60 points, the pass line is 60 points
Input: Enter 10 integers, value 0~100
Output: Output pass line, multiples of 10
Input Sample: 61 51 49 30 20 10 70 80 90 99
Output Sample: 50
The code is as follows:
#include <iostream>using namespace std;void insertsort (int a[]); int getnum (int a[]); void main () {cout<< " Please inter scores of students (0~100): "<<endl;int a[10]={0};int x;for (int i=0;i<10;i++) {Cin>>x;a[i] =x;} Cout<<getnum (a);} void Insertsort (int a[]) {for (int i=1;i<10;i++) {int Currentelement=a[i];int k;for (k=i-1;k>=0&&a[k]> currentelement;k--) {a[k+1]=a[k];} A[k+1]=currentelement;} for (int i=0;i<10;i++) {cout<<a[i]<< "";} Cout<<endl;} int getnum (int a[]) {insertsort (a); if (a[0]>=60) {return 60;} int N=a[4]/10;return n*10;}
Title two: Number of lights
Description: A corridor with n (1≤n≤65535) lamp in sequence, from beginning to end numbered 1, 2, 3 、... n-1, N. Each lamp is controlled by a pull-wire switch. At first, the lights were all closed.
There were n students walking through the corridor. The first student pulls the switch of the electric light with a number of multiples of 1, then the second student pulls the switch of the light bulb, which is usually a multiple of 2, and the third student pulls the switch of the electric light with a number of multiples of 3; N students according to the provisions of the walk, there are several lights in the corridor. Note: The number of lights is the same as the number of students.
Input: Number of lights
Output: Number of lights on
Example input: 3
Sample output: 1
The code is as follows:
#include <iostream> #include <vector>using namespace std;int countlight (int n); void Main () {int n=3; cout<<countlight (n);} int countlight (int n) {if (n<1| | n>65535) {return 0;} vector<int >a (n,0); Vector<bool> A_flag (n,1); for (int i=0;i<n;i++) {a[i]=i+1;} int k=2; while (K<=n) {for (int i=0;i<n;i++) {if (a[i]%k==0) {a_flag[i]=!a_flag[i];}} k++;} int res=0; for (int i=0;i<n;i++) {res+=a_flag[i];} return res;}
Huawei Machine Test paper--passing score, light number