-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10.42.cpp
50 lines (42 loc) · 796 Bytes
/
10.42.cpp
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
#include<iostream>
#include<list>
#include<string>
#include<algorithm>
#include<fstream>
#include<stdexcept>
void elimDups(std::list<std::string> &words);
int main(int argc,char* argv[])
{
std::list<std::string> ls;
std::ifstream in(argv[1]);
if(in){
std::ofstream ou(argv[2],std::ofstream::app);
if(ou){
std::string s;
while(in >> s){
ls.push_back(s);
}
for(auto s : ls){
std::cout << s << " ";
ou << s << " ";
}
ls.sort();
ls.unique();
std::cout << std::endl;
ou << std::endl;
for(auto s : ls){
std::cout << s << " ";
ou << s << " ";
}
ou.close();
}
else{
std::cerr << "could not open " << argv[2];
}
}
else{
throw std::runtime_error(std::string("could not open") + argv[1]);
}
system("pause");
return 0;
}