#include #include #include using namespace std; int main(int argc, char **argv) { double granularity; map histogram; map ::iterator hit; int bucket; double d; double total; if (argc != 2) { cerr << "usage: histogram granularity\n"; exit(1); } total = 0; sscanf(argv[1], "%lf", &granularity); while (cin >> d) { bucket = floor(d /granularity); histogram[bucket]++; total++; } for (hit = histogram.begin(); hit != histogram.end(); hit++) { d = hit->first; d *= granularity; d += (granularity/2.0); cout << d << " " << hit->second/total << endl; } return 0; }