blob: 27c6bcb4830ef17316c10a4b690d92252c124257 (
plain)
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
45
46
47
48
49
50
51
52
53
54
55
56
57
|
#include <iostream>
#include <vector>
/*
*
* 5.16
*
*
*/
void idiomatic_while(std::vector<int> &idw) {
int i = 0;
while(std::cin >> i) {
idw.push_back(i);
}
}
void idiomatic_for(std::vector<int> &idf) {
for(auto a : idf) {
std::cout << a << std::endl;
}
}
void nonidiomatic_while(std::vector<int> &nidw) {
auto iter = nidw.cbegin();
while(iter != nidw.cend()) {
std::cout << *iter++ << std::endl;
}
}
void nonidiomatic_for(std::vector<int> &nidf) {
int i = 0;
for( ; std::cin >> i ; ) {
nidf.push_back(i);
}
}
int main (int argc, char *argv[]) {
if(argc > 2 || argc < 2) { return -1; }
std::string argv_s = argv[1];
std::vector<int> iv1;
std::vector<int> iv2;
if(argv_s == "1") {
idiomatic_while(iv1);
idiomatic_for(iv1);
} else if (argv_s == "2") {
nonidiomatic_for(iv2);
nonidiomatic_while(iv2);
}
return 0;
}
|