-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot_hist.cpp
37 lines (33 loc) · 896 Bytes
/
plot_hist.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
/**************************************************************
* This is a simple function to count the weight distribution.
* This function will first read 'weight.txt' and count
*************************************************************/
#include <iostream>
#include <unordered_map>
#include <fstream>
#include <utility>
#include <assert.h>
using namespace std;
int main(int argc, char ** argv){
ifstream f_in("weights.txt");
if(!f_in.is_open()){
cout<<"Cannot open file: weights.txt\n"
<<"This file might not exist!"<<endl;
assert(f_in.is_open());
}
unordered_map<int, int> my_hash;
int w;
while(f_in>>w){
if(my_hash.find(w) == my_hash.end()){
my_hash.insert(make_pair(w, 1));
}
else{
++my_hash[w];
}
}
// print out the results:
for(auto p : my_hash){
cout<<"Weight "<<p.first<<" has "<<p.second<<endl;
}
return 0;
}