Summary of Huawei machine test questions

Posted by weyes1 on Sun, 20 Feb 2022 17:05:55 +0100

Python wechat ordering applet course video

https://edu.csdn.net/course/detail/36074

Python actual combat quantitative transaction financial management system

https://edu.csdn.net/course/detail/35475
Generally speaking, the difficulty of the questions in the recent year is simple and medium.

The questions are divided into five categories: character, sorting, search and algorithm questions, of which the binary tree is taken out separately

Degree of difficulty: 80% belong to the category of simple questions, and the rest belong to luck questions.

I character string

Frequently tested questions are: (string comparison, string splicing, string sorting, whether it is a common substring, string reversal, string rearrangement;)

For string questions, just use the map function directly, and the remaining 2.5% of the questions can use the for loop to output the results;

II Sort class

The frequently tested questions are: (K letter combinations, ask the first character or number, and the children are sorted according to their height and weight;)

III Find class

Frequently asked questions are: (find the median, children find the height and weight;)

IV Algorithmic questions (BFS, DFS;)

Frequently asked questions are: (number of people on the diagonal, maze, optimal planning, knapsack problem;)

**The above are several types of high-frequency test contents, and the following are some functions commonly used in the test******

1.getline function, which can read the whole line, including leading and embedded spaces, and store it in the string object.

When cin reads data, it starts reading as soon as it touches the first non white space character, and stops reading when it reads the next white space character.

getline(cin, inputLine);   give an example: getline(cin, name);

The 2.sort function is included in the c++ standard library with header file #include, and the sorting method in the standard library can be used to sort the data.

void sort (RandomAccessIterator first, RandomAccessIterator last, Compare comp); 

#include
#include
using namespace std;
bool cmp(int a,int b);
main(){
  //The third parameter of sort function is defined by itself, and the implementation is from large to small
  int a[]={45,12,34,77,90,11,2,4,5,55};
  sort(a,a+10,cmp);
  for(int i=0;i<10;i++)
    cout<" ";
}
//Custom function
bool cmp(int a,int b){
  return a>b;
}

3.substr function, which returns a string containing a copy of n characters from pos in S (the default value of pos is 0, and the default value of n is s.size() - pos, that is, the whole s will be copied by default without parameters)

#include
#include
using` `namespace` `std;
int` `main()
{
  string s(``"12345asdf"``);
  string a = s.substr(0,5);   ``//Get the string with length of 5 from bit 0 in string s
  cout << a << endl;
}

4.atoi function, which converts char [], a function that converts a string into int in the c + + standard library.

int i_dec = std::stoi (str_dec,&sz);  
int i_hex = std::stoi (str_hex,nullptr,16);  
int i_bin = std::stoi (str_bin,nullptr,2);  
int i_auto = std::stoi (str_auto,nullptr,0);   
std::cout << str_dec << ": " << i_dec << " and [" << str_dec.substr(sz) << "]\n";  
std::cout << str_hex << ": " << i_hex << '\n';  
std::cout << str_bin << ": " << i_bin << '\n';  
std::cout << str_auto << ": " << i_auto << '\n'

5.c_str(). The string class member function of the standard library obtains a C-type character array from a string

#include 
//A string containing cstring is required
#include 
using namespace std;
 
int main()
{
    //string-->char*
    //c\_ The str() function returns a pointer to the normal C string with the same content as this string
 
    //The data of this array is temporary. When a member function that changes these data is called, the data in it will become invalid.
    //Therefore, either convert the current use first, or copy its data to the memory that the user can manage
    const char *c;
    string s = "1234";
    c = s.c_str();
    cout<endl;
 s = "abcde";
 cout<endl;
}

6.sscanf, sscanf() function is used to read data in the specified format from the string, int sscanf (char *str, char * format [, argument,...]); Parameter str is the string of data to be read; Format is the format specified by the user; Argument is a variable used to save the read data.

The number of parameters is returned if successful, and - 1 if failed. The error reason is stored in errno.

sscanf() will convert the string of parameter str according to the parameter format (format string) and format the data (for format string, please refer to scanf()), and the converted result will be stored in the corresponding variable.

Similar to scanf(), sscanf() is used for input, except that scanf() takes the keyboard (stdin) as the input source and sscanf() takes the fixed string as the input source.

#include 
int main(void)
{
    char str[100] ="123568qwerSDDAE";
    char lowercase[100];
    int num;
    sscanf(str,"%d %[a-z]", &num, lowercase);
    printf("The number is: %d.\n", num);
    printf("The lowercase is: %s.", lowercase);
    return 0;
}

Common traversal methods:

dfs and bfs

The difference between recursion and dynamic programming

Similarities:
Recursion and dynamic programming are two very basic algorithms. They use the idea of divide and conquer to disassemble a big problem into a small problem.

difference:
1. Recursion is from top to bottom (from big problems to small problems), while dynamic programming is from bottom to top (solving small problems first and then to big problems);
2. Dynamic programming will store the results of each small problem, so its calculation speed will be faster than recursion. (the cost is that the spatial complexity of dynamic programming is higher, that is, the time exchanged with space).
3. Dynamic programming is realized by recursion, which is realized by function.

————————————Split line -————————————

Questions that need to learn knowledge points

5. Write a program to accept a hexadecimal number and output the decimal representation of the value.

#include
using namespace std;
int main(){
    string a;
    while(getline(cin,a)){
        int res=0;
        int pos=a.find('x');
        for(int i=pos+1;iint tmp=0;
 if(a[i]>='A'&&a[i]<='F'){
 tmp=10+(a[i]-'A');
 }
 else{
 tmp=a[i]-'0';
 }
 res=res*16+tmp;
 }
 cout<endl;
 }
 return 0;
}

You need to know the principle of converting decimal to hexadecimal: the hexadecimal number is calculated from low to high (i.e. from right to left). The weight of bit 0 is the 0 power of 16, the weight of bit 1 is the 1 power of 16, and the weight of bit 2 is the 2 power of 16. Increase it successively, and the value added to the final result is the value of decimal.

Hexadecimal is every 16 into 1. The number of hexadecimal is 0123456789ABCDEF.

Example: the steps of converting hexadecimal (2B)H to decimal are as follows:

\1. Bit 0 B x 16^0 = 11;

\2. Bit 1 2 x 16^1 = 32;

\3. Reading, add the result value, 11 + 32 = 43, that is, (2B)H=(43)D.

For other binary conversion, please see the great God blog:

https://blog.csdn.net/gaizai/p/4233780.html#_labelConvert13

Topics: Python Algorithm computer