The recollection of the written test questions of the software engineering master in 2018, Jilin University School of software

Note: the title of written test programming is handwritten, with a full score of 150 and a time of 2 hours.
This year is the second year of enrollment. For the first year of re examination, please refer to
https://blog.csdn.net/qq_27513221/article/details/79424084
In terms of topic types, there are mainly recursion, enumeration, array and string types. It's easier to generalize

1. Judgment of "completion" (40 points)

The sum of all factors of a positive integer is equal to itself. Such a number is called a perfect number. For example: 1 + 2 + 3 = 6, then 6 is the complete number. Output all completions up to 100.

Reference code:

#include<bits/stdc++.h> //Include all library functions 
using namespace std;

int isWholeNUM(int n){  //Use function to judge 
    int sum = 0;
    for(int i = 1;i < n;++i){
        if(n%i == 0)
            sum += i;
    }
    if(sum == n) return 1;
    else return 0;
}

int main(){
    for(int i = 1;i < 100;++i){
        if(isWholeNUM(i))
            cout<<i<<endl;
    }
    return 0;
} 

2. Sequence output (40 points)

Assume that the sequence satisfies:

  1. The first digit is 1;
  2. The second digit is 2;
  3. The odd digit is the sum of the first two terms, and the even digit is the difference between the first two terms;

Sort and output the sequence within 100 in ascending order

Reference code:

#include<bits/stdc++.h>
using namespace std;

int r_list(int n){
    if(n == 1) 
        return 1;
    else if(n == 2)
        return 2;
    else if(n%2 != 0)
        return r_list(n - 1) + r_list(n -2);
    else if(n%2 == 0)
        return r_list(n - 1) - r_list(n -2);
}

int main(){
    int num;
    vector<int> array;
    for(int i = 1;i <= 100;++i){
        num = r_list(i);
        array.push_back(num);
    }
    sort(array.begin(),array.end());
    for(int i = 0;i < array.size();++i)
        cout<<array[i]<<endl;
    return 0;
} 

3. Shortest section (40 points)

There are 100 points on the plane. Any two points can be connected into a line segment. If there is a point (x1,y1) and a point (x2,y2), the distance between the two points is

(x1−x2)2+(y1−y2)2−−−−−−−−−−−−−−−−−−−√(x1−x2)2+(y1−y2)2

Find the shortest of all line segments

Reference code:

#include<bits/stdc++.h>
using namespace std;

struct point{
    int x;
    int y;
} array[99];    //Contains 100 points, starting at 0 

int main(){
    int length = 0,max = 0;
    for(int i = 0;i < 100;++i)          //Enter coordinates for 100 points 
        cin>>array[i].x>>array[i].y;
    for(int i = 0;i < 100;++i){         //Calculate the length of all combined segments between 100 points 
        for(int j = 0;j < 100;++j){
            length = (array[i].x - array[j].x)^2 + (array[i].y - array[j].y)^2;
            if(max < length)
                max = length;
        }
    } 
    cout<<sqrt(max);
    return 0;
}

4. Number of 0 strings (30 points)

Input a sequence. Two or more consecutive zeros are called zero strings. If it is 001000, the number of 0 strings is 2. The input ends with 2 and asks if there are two or more 0 strings in the sequence

#include<bits/stdc++.h>
using namespace std;

int main(){
    string num;
    int m = 0,n = 0;
//  While ((CIN > > Num)! ='2 '); / / the question should be this way. When inputting 2, the input will be terminated automatically, but an error will be reported 
    cin>>num;                   //So manual input 
    for(int i = 0;i < num.length();++i){
        if(num[i] == '0')
            m++;
        else 
            m = 0;
        if(m >= 2 && num[i + 1] != '0')
            n++;    
    }
    if(n >= 2)
        cout<<"OK"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
} 

Keywords: Programming

Added by drax007 on Mon, 06 Apr 2020 03:08:26 +0300