常用stl
rotate & rotate_copy
循环旋转序列内元素
template< class ForwardIt >
ForwardIt rotate(ForwardIt first, ForwardIt middle, ForwardIt last);
template< class ForwardIt1, class ForwardIt2 >
ForwardIt2 rotate_copy(ForwardIt1 first, ForwardIt1 middle, ForwardIt1 last, ForwardIt2 d_first);
accumulate
区间计算,具体计算函数为第四个参数(默认为加法), init为初始值
#include <numeric>
T accumulate(InputIt first, InputIt last, T init, BinaryOperation op);
ex:
#include <numeric>
#include <vector>
#include <string>
#include <iostream>
using namespace std;
int main() {
vector<string> words = {"Hello", " ", "World", "!"};
string sentence = accumulate(words.begin(), words.end(), string(""));
cout << sentence << endl; // 输出 "Hello World!"
}
以及对浮点数需要double(0)或(0.0)

浙公网安备 33010602011771号