-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIndex.cpp
45 lines (41 loc) · 987 Bytes
/
Index.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
#include <iostream>
#include <map>
#include <sstream>
#include <vector>
#include <fstream>
using namespace std;
int main() {
map<string, vector<pair<int, int> > > dict;
string line, word;
stringstream stream;
ifstream myfile("input.txt");
ofstream out;
out.open("output.txt");
int line_num = -1, word_num = 0;
if (myfile.is_open())
{
while (getline(myfile, line)) {
stringstream stream(line);
line_num++; word_num = -1;
while (stream >> word) {
word_num++;
dict[word].push_back(make_pair(line_num, word_num));
}
}
}
for (pair<string, vector<pair<int, int> > > p : dict) {
out << p.first << " " << p.second.size() << "[";
for (int i = 0; i < p.second.size(); ++i) {
out << "(" << p.second[i].first << "," << p.second[i].second << ")";
if (i != p.second.size() - 1) {
out << ",";
}
}
out << "]" << endl;
}
out.close();
myfile.close();
std::cout << "done";
cin.get();
return 0;
}