COMBINATORIAL_BLAS 1.6
 
Loading...
Searching...
No Matches
components.cpp
Go to the documentation of this file.
1#include <iostream>
2#include <string>
3#include <fstream>
4#include <sstream>
5#include <vector>
6#include <algorithm>
7#include <chrono>
8#include <functional>
9#include <cmath>
10#include <map>
11#include <tuple>
12#include <cstdlib>
13#include <cstdio>
14#include <limits>
15
16using namespace std;
17
18
19
20int main(int argc, char* argv[])
21{
22 if(argc < 2)
23 {
24 cout << "Usage: ./components <components_file>" << endl;
25 return 0;
26 }
27
28 string vname, compname;
29 ifstream inputvert(argv[1]);
30 map<string, int> compcounts;
31 vector< pair<int, string > > countbyname;
32
33 while(inputvert >> vname)
34 {
35 inputvert >> compname;
36 auto it = compcounts.insert(make_pair(compname,1));
37 if (!it.second) // already there
38 {
39 (it.first->second)++;
40 }
41 }
42 cout << "distinct components " << compcounts.size() << endl;
43
44 for (auto it = compcounts.begin(); it != compcounts.end(); ++it)
45 {
46 countbyname.push_back(make_pair(it->second, it->first));
47 }
48sort(countbyname.begin(), countbyname.end());
49for (auto it = countbyname.begin(); it != countbyname.end(); ++it)
50{
51 cout << it ->second << " " << it->first << endl;
52}
53
54}
int main()
Definition Driver.cpp:12