Created
November 21, 2010 17:52
-
-
Save jviereck/708956 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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