-
Notifications
You must be signed in to change notification settings - Fork 0
/
10.4.2.2.cc
76 lines (55 loc) · 1.4 KB
/
10.4.2.2.cc
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <iterator>
#include <vector>
#include <string>
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
int test1()
{
ifstream fin("test");
istream_iterator<string> in(fin);
istream_iterator<string> eof;
vector<string> svec(in, eof);
for(auto & s : svec)
cout << s << endl;
return 0;
}
void test2(){
istream_iterator<int> in(cin);
istream_iterator<int> eof;
ostream_iterator<int> out(cout, " ");
vector<int> ivec(in, eof);
sort(ivec.begin(), ivec.end());
copy(ivec.begin(), ivec.end(), out);
}
void test3(){
istream_iterator<int> in(cin);
istream_iterator<int> eof;
ostream_iterator<int> out(cout, " ");
vector<int> ivec(in, eof);
sort(ivec.begin(), ivec.end());
/* 依赖于提前排序,=> 相同的放在一起 */
unique_copy(ivec.begin(), ivec.end(), out);
}
void test4(string infile, string outfile1, string outfile2){
ifstream fin(infile);
ofstream fout1(outfile1);
ofstream fout2(outfile2);
istream_iterator<int> in(fin);
istream_iterator<int> eof;
ostream_iterator<int> out1(fout1, " ");
ostream_iterator<int> out2(fout2, "\n");
while(in != eof){
if(*in & 1)
out1 = *in;
else
out2 = *in;
++in;
}
}
int main(int argc, char const *argv[])
{
test4("infile", "outfile1", "outfile2");
return 0;
}