Блог пользователя woodfishhhh

Автор woodfishhhh, история, 12 месяцев назад, По-английски

First blog .Yeee~

count() int count_result = count(numbers.begin(), numbers.end(), 2);

Here, it will count the number of elements with the value of 2 in the numbers container and store the result in count_result.

hypot()

hypot is a function in the C++ standard library <cmath>, which is used to calculate the length of the hypotenuse of a right triangle, that is, the square root of the sum of the squares of the two right-angled sides. Mathematically, given the lengths of the two right-angled sides x and y of a right triangle, the length of the hypotenuse z can be calculated by the Pythagorean theorem: $$$z = \sqrt{x^2 + y^2}$$$.

max, min

min({dp[i — 1][j — 1] + 1, dp[i — 1][j] + 1, dp[i][j — 1] + 1}) You can compare multiple numbers like this.

remove s.erase(remove(s.begin(), s.end(), ' '), s.end()):

  1. remove(s.begin(), s.end(), ' ') will:

    o Traverse all the characters in the string.

    o Move all the characters that are not equal to the space character (' ') forward.

    o Return an iterator pointing to the new logical end.

  2. s.erase(..., s.end()) will:

    o Start from the new logical end.

    o Delete all the characters from the new logical end to the end of the original string.

In this way, we can delete all the spaces (or other things) in the string s.

Points for attention 1. remove only accepts forward iterators. 2. It will not change the capacity of the container, only the size. 3. For associative containers (such as set, map, etc.), their own erase method should be used.

Transform

It can modify the elements in an array (string) according to a lambda expression.

transform(str.begin(), str.end(), str.begin(), [](unsigned char c) { return std::tolower(c); });

  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится

»
12 месяцев назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

amazing