Skip to content

Instantly share code, notes, and snippets.

@justinvh
Last active August 29, 2015 13:55
Show Gist options
  • Select an option

  • Save justinvh/8778142 to your computer and use it in GitHub Desktop.

Select an option

Save justinvh/8778142 to your computer and use it in GitHub Desktop.
#include <vector>
#include <iostream>
int main()
{
std::vector<std::pair<int, char>> tally(128);
for (int i = 0; i < 128; i++) {
tally[i].second = i;
}
char c;
while (EOF != (c = fgetc(stdin))) {
tally[c].first += 1;
};
std::sort(tally.begin(), tally.end());
for (auto const& pair : tally) {
if (pair.second) printf("%c %d\n", pair.second, pair.first);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment