Skip to content

Instantly share code, notes, and snippets.

@jviereck
Created November 21, 2010 17:52
Show Gist options
  • Save jviereck/708956 to your computer and use it in GitHub Desktop.
Save jviereck/708956 to your computer and use it in GitHub Desktop.
// Informatik - Serie 8 - Aufgabe 87
// Programm: frequencies.cpp
// Autor: Julian Viereck (Gruppe K)
#include<iostream>
#include<ios> // for std::noskipws
int main ()
{
char t;
unsigned int i;
unsigned int count_chars[27];
unsigned int count = 0;
// Set all entries of count_chars to 0.
for (i = 0; i < 27; ++i) {
count_chars[i] = 0;
}
// Loop over all characters from the input stream.
while (std::cin >> t) {
++count;
if (t >= 65 && t <= 90) {
++count_chars[t - 65];
}
else if (t >= 97 && t <= 122) {
++count_chars[t - 97];
}
else {
++count_chars[26];
}
}
std::cout << "Frequencies:\n";
for (i = 0; i < 26; ++i) {
t = 97 + i;
std::cout << t << ": " << count_chars[i] << " of " << count << "\n";
}
std::cout << "Other: " << count_chars[i] << " of " << count << "\n";
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment