-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaccumulate.cpp
More file actions
44 lines (34 loc) · 1.13 KB
/
Copy pathaccumulate.cpp
File metadata and controls
44 lines (34 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <iostream>
#include <vector>
#include <climits> // INT_MAX
#include <numeric> // accumulate
using namespace std;
int main(void){
// vector, arrayに対するaccumulate
vector <int> vec;
vec.push_back(1);
vec.push_back(4);
vec.push_back(5);
int hoge[3] = {100000000,200000000,2};
cout << "INT_MAX = " << INT_MAX << endl;
cout << "LLONG_MAX = " << LLONG_MAX << endl;
//sum
//array
cout << accumulate(&hoge[0],&hoge[3],0) << endl;
//vector
cout << accumulate(vec.begin(),vec.end(),0) << endl;
//mult
//array(long longに対応)
cout << accumulate(&hoge[0],&hoge[3],1ll,multiplies<long long>()) << endl;
//vector
cout << accumulate(vec.begin(),vec.end(),1,multiplies<int>()) << endl;
vector <string> sVec;
sVec.push_back("fizz");
sVec.push_back("bazz");
sVec.push_back("foobar");
string hogehoge[2] = {"Tohoku","University"};
//stringのconcetenateもできる
cout << accumulate(&hogehoge[0],&hogehoge[2],string()) << endl;
cout << accumulate(sVec.begin(),sVec.end(),string()) << endl;
return 0;
}