Excerpt from "benevolent Forum postgraduate computer machine test Guide"

2020-02-11


 

In fact, no know-how to realize their dreams, that is a little more than others to get up early, stay up late a little, prepare a little earlier than others, a little hard. PubMed, too.


 

A qualified write code for computer science students, even if luck was admitted to a graduate student, but also to the future of unemployment sentenced to probation only.


 

 1_ [scratch]

  • Ability to inspect the machine test:
    1. The real problem is abstracted into mathematical problems
    2. The expertise to use mathematical models
    3. The preparation of the design algorithm into an executable program

  (Including 1: program code written in classical algorithm 2: able to design their own program code conversion algorithm 3: robustness, ie, written procedures able to cope with a variety of test data)

 

  • Special judge questions (Special Judge) : Such problems may exist more in line with a set of solutions to answer points conditions, any required output

 

  • Most questions only do limit the time, this time to have " space for time " thinking. 11:52:07

[Entry] 2_ Classic 12:25:59

[Sort] 2.1_

 

[2.1.1_ sort of basic data types]

 

  • When the continuous need to test multiple sets of data, cycling conditions how to write?
while(scanf("%d",&n)!=EOF)
  1. scanf () is the return value, the function will return the number of input variables assigned success (in this example 1, i.e., n)
  2. EOF (end of file) is -1, the scanf returns EOF when n is not assigned, out of the loop
  3. The cycling conditions used for determination: test both sets of data, but the normal exit after entry.
  • Different environments for compiling loop variable i indicates different scopes
  1. Standard C ++, i is limited scope for internal circulation; so we can redefine the variables for a plurality of cycles i
  2. VC6.0, after the exit for loop, the variable i still visible; there is no need to redefine i, i is initialized to simply follow in the for loop.
  • Bubble Sort

 

1 for(int i = 0; i < n; i ++){
2     for(j = 0; j < n-1-i; j ++){
3         if(buf[j] > buf[j + 1]){
4           int  tmp = buf[j];
5           buf[j] = buf[j + 1];
6           buf[j + 1] = tmp; 
7       }  
8   }
9 }

C ++ has fast sorting library function , it can contain #include <algorithm> called directly after the header file

  • sort (first, last, cmp) function

The third parameter may be omitted, which defaults to ascending

To obtain the results in descending order, it can be rewritten CMP (), the default return x <y; Y to return <X; 13:52:24

sort () function in accordance with the operator is less than "<" to sequencing, the small front.

[2.1.2_ sort of structure]

  •  Redefine the comparison function cmp ()
 1 struct stu{
 2      char name[101];
 3      int age;
 4      int score;
 5  }buf[1000];
 6  bool cmp(stu a, stu b){
 7      if(a.score != b.score) return a.score < b.score
 8      int tmp = strcmp(a.name , b.name);
 9      if(tmp != 0) return tmp<0;
10      else return a.age < b.age 
11 }   
  • Further, in stu structural body may be "less-than operator overloading operator " i.e. operator <(), the collation will be described, case sort () function is not necessary that the third parameter. (Promoting the use of)

 

 1 struct stu{
 2 char name[101];
 3 int age;
 4 int score;
 5 bool operator < (const stu &b) const {
 6   if (score != b.score) return score < b.score;
 7   int tmp = strcmp(name , b.name);
 8   if(tmp != 0) return tmp < 0;
 9   else return age < b.age;          
10   }
11 }buf[1000];

 

[2.2_ date kind of problem]

[2.2.1_ date difference (Range of) ]

Guide: Section of the original unified range of issues to determine the starting point

For example, the number of days between 1 January 0000 and the date the origin of the time difference

This will be before the program really started pretreatment - the number of days to calculate all dates and the date of the origin of the difference and saved

  • When need to open up a large amount of memory space (e.g., buf [5001] [13] [32])
  1. In vitro function is defined, the global variable
  2. In the application using the dynamic variable space function malloc function, etc.

Pretreatment is an important means space for time.

  • leap year

 

1 #define ISYEAP(x) x % 100 != 0 && x % 4 == 0 || x % 400 == 0 ? 1 : 0

 

Define a macro to determine whether it is a leap year


 

 

To link itself with the address data stored in the data is the basic idea of ​​Hash.

  • For the most common time limit 1 second algorithm complexity is usually not more than one million level (7), a maximum of seven

[2.2.2_ seeking the week] 2020-02-11 18:05:25

 2020-02-12 10:46:57

Act One:

  Ideas: still on 1 January 0000 as the date of origin, processing the number of days between each date and date of origin is poor, then find a given date and the number of days difference between today and know that today is the day of the week, for In addition to the difference between the number of days taken more than 7 you can.

Act II:

Using Zeller (Zeller) equation, as follows from the known picture content almost https://zhuanlan.zhihu.com/p/79290515

 

 

 

 

 

 

 

 

 

 

 

 

 

 

--From "benevolent Forum postgraduate computer machine test Guide"

Guess you like

Origin www.cnblogs.com/onemorestep/p/12294060.html