(A) programming skills

 When determining whether two floating-point numbers a and b are equal, do not use a == b; should determine the absolute value of the difference between fabs (ab) is smaller than a certain threshold, for example: 1e - 9;

Determining whether an integer is an odd number x% 2 = 0;! Do not use x% 2 == 1 ;, x should be negative.

With the value of char as a subscript (for example: the number of times each character appears in the statistics), taking into account the char may be negative. It was taken into account, the first strong and then converted to the unsigned int as a subscript, it is still wrong. The correct approach is to first turn strong unsigned char, and then as a subscript

vector and string arrays dynamic allocation priority

  First of all: in performance, due to the vector to ensure continuous memory, so once the assignment, its performance with the original array is fairly:

  Second: If new, means you have to make sure to use delete, you forget the bug will have in the back, and so should write a line delete, code is not short enough.

  Again, multidimensional array, then only a one new, for example:      

       int **array=new int *[row_now];

  for(int i=0;i<row;++i)

  {

    ary[i]=new int [col_num];

  } 

If vector then be able to get a line of code:

vector<vector<int> >    ary(row_num,vector<int> (col_num,0))

 

Guess you like

Origin www.cnblogs.com/xcb-1024day/p/11221879.html