-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchecker.cpp
58 lines (53 loc) · 966 Bytes
/
checker.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
51
52
53
54
55
56
57
58
#include<bits/stdc++.h>
using namespace std;
map<string,std::vector<string> >hashMap;
void checkFile(ifstream &ifs)
{
if(!ifs.is_open())
{
cout << "Input file doesn't exist";
exit(0);
}
}
int main(int argc, char** argv)
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
if(argc < 4)
{
cout << "Usage: ./a.out inputR inputS outputFile";
return 0;
}
ifstream input;
input.open(argv[1]);
checkFile(input);
string X, Y, Z;
int pos;
while (getline (input, Y))
{
while ((pos = Y.find(" ")) != std::string::npos)
{
X = Y.substr(0, pos);
Y.erase(0, pos + 1);
}
hashMap[Y].push_back(X);
}
input.close();
input.open(argv[2]);
checkFile(input);
ofstream output;
output.open(argv[3]);
while (getline (input, Z))
{
while ((pos = Z.find(" ")) != std::string::npos)
{
Y = Z.substr(0, pos);
Z.erase(0, pos + 1);
}
for (auto x:hashMap[Y])
{
output << x <<" "<< Y <<" "<< Z <<"\n";
}
}
return 0;
}