File: components.cpp

package info (click to toggle)
combblas 2.0.0-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 190,476 kB
  • sloc: cpp: 55,912; ansic: 25,134; sh: 3,691; makefile: 548; csh: 66; python: 49; perl: 21
file content (54 lines) | stat: -rw-r--r-- 1,139 bytes parent folder | download
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
#include <iostream>
#include <string>
#include <fstream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <chrono>
#include <functional>
#include <cmath>
#include <map>
#include <tuple>
#include <cstdlib>
#include <cstdio>
#include <limits>

using namespace std;



int main(int argc, char* argv[])
{
    if(argc < 2)
    {
       cout << "Usage: ./components <components_file>" << endl;
        return 0;
    }
    
    string vname, compname;
    ifstream inputvert(argv[1]);
    map<string, int> compcounts;
    vector< pair<int, string > > countbyname;
    
    while(inputvert >> vname)
    {
	inputvert >> compname;
	auto it = compcounts.insert(make_pair(compname,1));
	if (!it.second)	// already there
	{
		(it.first->second)++;
	}
    }
    cout << "distinct components " << compcounts.size() << endl;

   	for (auto it = compcounts.begin(); it != compcounts.end(); ++it)
	{
		countbyname.push_back(make_pair(it->second, it->first));
	} 
sort(countbyname.begin(), countbyname.end());
for (auto it = countbyname.begin(); it != countbyname.end(); ++it)
{
	cout << it ->second << " " << it->first << endl; 
}
    
}