All pastes #2038832 Raw Edit

Something

public cpp v1 · immutable
#2038832 ·published 2011-01-05 16:02 UTC
rendered paste body
/* *      statistik.cpp * *      Copyright 2008 Janek 'Rechteck' Walkenhorst <janek@jpwalkenhorst.de> * *      This program is free software; you can redistribute it and/or modify *      it under the terms of the GNU General Public License as published by *      the Free Software Foundation; either version 2 of the License, or *      (at your option) any later version. * *      This program is distributed in the hope that it will be useful, *      but WITHOUT ANY WARRANTY; without even the implied warranty of *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the *      GNU General Public License for more details. * *      You should have received a copy of the GNU General Public License *      along with this program; if not, write to the Free Software *      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, *      MA 02110-1301, USA. */#include <iostream>using namespace std;int **tabelle[256];void initTabelle(){  for (int i = 0; i < 256; i++) {    tabelle[i]=new int*;    tabelle[i][0]=NULL;  }}void baueTabelle(const char *gruppe, int *zaehler){  char zeichen;  while ((zeichen = *(gruppe++))) {    int **alt = tabelle[(int)zeichen];    int laenge = 0;    while (*(alt++)) { // count the elements      laenge++;    }    int **neu;    neu = new int*[laenge+1]; // allocate new memory (+ space for the new entry)    alt = tabelle[(int)zeichen];    for (int i = 0; i <= laenge; i++) { // copy old entries      neu[i] = alt[i];    }    neu[laenge] = zaehler; // append the new entry    neu[laenge+1] = NULL; // mark the end    delete alt;    tabelle[(int)zeichen] = neu;  }}int main(){  int anzahlGrossbuchstaben = 0;  int anzahlKleinbuchstaben = 0;  int anzahlLeerzeichen = 0;  int anzahlVokale = 0;  int anzahlKonsonanten = 0;  int laenge;  initTabelle();  baueTabelle("ABCDEFGHIJKLMNOPQRSTUVWXYZ", &anzahlGrossbuchstaben);  baueTabelle("abcdefghijklmnopqrstuvwxyz", &anzahlKleinbuchstaben);  baueTabelle("AaEeIiOoUu", &anzahlVokale);  baueTabelle("BbCcDdFfGgHhJjKkLlMmNnPpQqRrSsTtUuVvWwXxYyZz", &anzahlKonsonanten);  baueTabelle(" ", &anzahlLeerzeichen);  while (! cin.eof()) {    char zeichen;    cin.get(zeichen);    laenge++;    int **zeiger = tabelle[(int)(unsigned char)zeichen];    int *zaehler;    while ((zaehler=*(zeiger++))) {      (*zaehler)++;    }  }  cout << "Grobuchstaben: " << anzahlGrossbuchstaben << endl;  cout << "Kleinuchstaben: " << anzahlKleinbuchstaben << endl;  cout << "Vokale: " << anzahlVokale << endl;  cout << "Konsonanten: " << anzahlKonsonanten << endl;  cout << "Leerzeichen: " << anzahlLeerzeichen << endl;  return 0;}