-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtabulate.cc
More file actions
63 lines (53 loc) · 1.18 KB
/
tabulate.cc
File metadata and controls
63 lines (53 loc) · 1.18 KB
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
#include <iostream>
#include <map>
#include <iterator>
#include <string>
#include <sstream>
#include <fstream>
using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::map;
using std::istringstream;
using std::ifstream;
int
main(int argc, const char *argv[])
{
map<string, map<unsigned int, unsigned int> > table;
string word,str;
unsigned int line;
istringstream stream;
ifstream file;
if(argc > 1){
file.open(argv[1],ifstream::in);
while(getline(file,str)){
stream.str(str);
++line;
while(stream>>word){
++table[word][line];
}
stream.str("");
stream.clear();
}
}else{
while(getline(cin,str)){
stream.str(str);
++line;
while(stream>>word){
++table[word][line];
}
stream.str("");
stream.clear();
}
}
for(map<string, map<unsigned int, unsigned int> >::iterator itr = table.begin(); itr != table.end();++itr){
cout<<endl<<itr->first<<" ";
for(map<unsigned int, unsigned int>::iterator itr1 = itr->second.begin(); itr1 != itr->second.end();++itr1){
cout<<itr1->first<<":"<<itr1->second<<" ";
}
}
cout<<endl;
file.close();
return 0;
}