The first question: how the c++/java/objective-c/c# language embodies the object-oriented thinking.
Regardless of the object-oriented language, the object-oriented idea is to implement object-oriented design through object-oriented features: inheritance, encapsulation, polymorphism (as if there is an abstraction, not to mention here).
In Java:
Inherited Java implements code reuse through inheritance. Inherited classes are called subclasses, and inherited classes are called parent classes. Subclasses cannot inherit member variables and methods in the parent class that have access rights private. Subclasses can override the parent class's methods and name member variables with the same name as the parent class. However, Java does not support multiple inheritance, which is the ability of a class to derive from multiple classes of superclass.
In the encapsulated Java language, an object is an encapsulation of a set of variables and related methods, where the variables indicate the state of the object, and the method indicates the behavior of the object. Through the encapsulation of objects, modularization and information hiding are realized. The information hiding of members in a class is implemented by applying certain access rights to the members of the class. Java has four different qualifiers: Public,private,protected,default.
Polymorphism polymorphism is manifested in two aspects: static polymorphism implemented by method overloading (compile-time polymorphism), and dynamic polymorphism implemented by method overrides (runtime polymorphism).
For C + +, I do not know much, I think it and Java in the object-oriented syntax and concepts have a lot of similarities, but Java is a completely object-oriented language, all things are in the class, and C + +, global variables, structures, enumerations, unions, and some of the concept of C is still exist At the same time, its main method is also outside of all classes.
As for C # and objective-c I do not contact, the personal feeling of the main ideas are similar, but some grammatical differences, focusing on the object-oriented four words, rather than what language.
The first question on to here, I fresh slag, written test is to save the character to check the leak, where not to hope the big God.
The second problem: the TCP protocol active connection and the active disconnection process.
If a is the active Open link Party, B is passively open the linked party.
Active Connection process:
b The TCP service process first creates the transport control block TCB, prepares to accept A's connection request, and then B is in the Listening state (Listen);
A TCP process is also the first to create a transport control block TCB, and then send a connection request packet to B, then the first synchronization bit syn=1, and select an initial sequence number seq=x. A enters the sync sent status (syn-sent).
b When the connection request message is received, if the connection is agreed, a confirmation is sent to a. In the confirmation message, the SYN and ACK are set to 1, the confirmation number ack=x+1, but also for their own selection of an initial sequence number seq=y. b Enter synchronous receive status (SYN-RCVD).
After receiving the confirmation from B, confirm to B. Confirm the ACK of the Message section 1, the confirmation number ack=y+1,seq=x+1, then the connection is established. A enters the established connection state (established).
If B receives a confirmation, B also enters the established connection state (established).
Active Disconnect Process:
A Send the connection release message, stop sending data, the message header FIN 1, the serial number seq=u,a into the terminating wait 1 status (fin-wait-1), wait for the confirmation of B.
b After receiving the connection release message segment, confirm that the confirmation number ack=u+1;seq=v,b into the shutdown Wait state (close-wait). After that, B may also send data to a, but a does not send data to B.
A receives the confirmation of B, enters the terminating Wait 2 state (fin-wait-2), waits for the connection release message sent by B.
If B has not sent data to a, then B sends a connection release message so that fin=1, serial number seq=w, confirmation number Ack=u+1,b Enter the final confirmation status (Last-ack), waiting for a confirmation.
A after receiving B's connection release message must be issued confirmation, ACK 1, confirmation number ack=w+1, serial number seq=u+1, enter the time waiting state (time-wait), A must wait for a time to wait for the counter to set the 2MSL (maximum message segment life) after a to enter the off (close) state. The connection is disconnected at this time.
The third question: what is the const meaning, what are the benefits of using const, and what are the meanings of the following five expressions?
const int A;
int *const A;
int const A;
const int *a;
int const *a const;
I think it should be in C or C + + to understand it, Const is a C language keyword, it is limited to a variable is not allowed to be changed. The use of const to some extent can improve the security and reliability of the program, in addition, when watching other people's code, clearly understand the role of Const, to understand the other side of the program also has some help.
For these five statements I am also a bit dizzy direct Baidu come up:
const int A; int const A; The two formulations are identical, indicating that a is an int constant.
const int *a; Indicates that a is a pointer that can point to an int constant or an int variable, and always treats the target it points to as an int constant. Can also be written as int const* A;
int * const A; Indicates that a is a pointer constant that must be fixed to an int variable when initialized, and then no longer point to another place.
int const * A const; it can be written as int const * const A; A is a pointer constant, which must be fixed to an int constant or int variable when initialized, and then no longer point to another place. It always treats the target it points to as an int constant. It can also be written as Const int* const A;
The next three algorithm design questions
Fourth question: write out the int strlen (const char *str) method, which requires that the method cannot have local or global variables.
At that time see can not define variables, think of a long period did not think of any good way, back to search the original is to use recursion, the following is the reference code:
int strlen (const char *str) { if (*str!= ') } {return 1 + strlen (++STR); } else { return 0; }}
Fifth question: The topic is roughly meaning to reverse an English sentence in order, but the word within the sequence of characters, for example: "The Misson of Baidu is to provide the best way for people to find information."
into "information. Find to people for means best the provide to be Baidu of Misson the ", the punctuation in the sentence as part of the word, do not distinguish.
I implemented in C, the code is as efficient as usual
#include <stdio.h> #include <string.h>int main () {int I,j,k,p,len,leni;char temp,s[1000];leni=0; Gets (s); Len=strlen (s); for (i=0;i< (LEN/2); i++)//flips entire string {temp=s[i];s[i]=s[len-1-i];s[len-1-i]=temp;} for (i=0;s[i]!= ';) {j=i; (s[j]!= ') && (s[j]!= '); j + +) Leni++;for (k=i,p=0;p< (LENI/2); k++,p++)// Flip each word { temp=s[k];//k each step from I plus a s[k]=s[i+leni-1-p];//a single tail pointer from i+leni-1 each time minus one s[i+leni-1-p]=temp;} Leni=0;if (s[j]== ")//Skip Space I=j+1;else if (s[j]== ' + ')//decide whether to end I=j;} Puts (s);}
Question sixth: Find out the 10 largest numbers from 1 million numbers. Write code and analyze complexity.
The problem until the end still did not come up with a good way, of course, the least efficient way is to iterate over and over again, so to count 10 million times, obviously not a good way.
Then consider dividing into multiple threads, such as dividing into 100 groups, 10,000 numbers per group, finding the largest 10 from each group, and finding the largest 10 from the 1000 found, which greatly improves the efficiency.
Because the problem is to write code, the individual think is not to adopt the method of grouping calculation, but to find a method of least number of operations, that is, the least time complexity.
On the test paper I used to construct a 10 number of arrays and in order from small to large, and then all the 1 million number to traverse, if it is smaller than the first number of the array to jump to the next number, if larger than it, replace the first element, and then sort the array, until all the number is traversed. This makes the entire time complexity worst for 1 million *10log10.
The algorithm on the net is to change the above array to a stacked sort, build a heap of only 10 elements, set the root node to the smallest number in the 10 number, and then begin to iterate through the array, if the number of nodes encountered is small, skip directly, encounter larger than the root node number, replace the root node, and then sort this, Ensure the characteristics of the stack head.
Hope that the great God guidance, can give a better solution.
Behind is the system design problem (these questions are relatively open, you can refer to some information on the internet to understand)
1: Based on mobile phone system platform, design an IM multi-person real-time voice chat system, including mobile phone and server side, based on some features of mobile phone system, to design this set of IM system.
2: Please describe the key performance indicators that need to be considered in this system design.
3: How to ensure the quality of real-time voice calls.
4: How to quickly migrate to multiple mobile system platforms (Android and iOS) scenarios.
5: Please draw the system structure diagram of the mobile phone terminal program.
Baidu Pen Test (mobile software development Post)