halo
This commit is contained in:
parent
50d0fcdb6d
commit
48ba00f7bb
2
.idea/Info2P5.iml
generated
2
.idea/Info2P5.iml
generated
@ -1,2 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<module classpath="CIDR" type="CPP_MODULE" version="4" />
|
|
55
strilist.c
Normal file
55
strilist.c
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#define NUM_DIGITS 10
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
char *strichlisten[NUM_DIGITS] = {NULL};
|
||||||
|
int counts[NUM_DIGITS] = {0};
|
||||||
|
int c;
|
||||||
|
|
||||||
|
// Initialisiere alle Strichlisten als leere Strings
|
||||||
|
for (int i = 0; i < NUM_DIGITS; ++i) {
|
||||||
|
strichlisten[i] = malloc(1);
|
||||||
|
if (!strichlisten[i]) {
|
||||||
|
fprintf(stderr, "Speicherfehler!\n");
|
||||||
|
// Speicher aufräumen
|
||||||
|
for (int j = 0; j < i; ++j) free(strichlisten[j]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
strichlisten[i][0] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Einlesen der Ziffern
|
||||||
|
while ((c = getchar()) != EOF) {
|
||||||
|
if (c >= '0' && c <= '9') {
|
||||||
|
int idx = c - '0';
|
||||||
|
counts[idx]++;
|
||||||
|
|
||||||
|
// Länge des alten Strings
|
||||||
|
size_t oldlen = strlen(strichlisten[idx]);
|
||||||
|
// Speicher für neuen String (+1 für neuen Strich, +1 für '\0')
|
||||||
|
char *neu = malloc(oldlen + 2);
|
||||||
|
if (!neu) {
|
||||||
|
fprintf(stderr, "Speicherfehler!\n");
|
||||||
|
// Speicher aufräumen
|
||||||
|
for (int j = 0; j < NUM_DIGITS; ++j) free(strichlisten[j]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
strcpy(neu, strichlisten[idx]);
|
||||||
|
neu[oldlen] = '|';
|
||||||
|
neu[oldlen+1] = '\0';
|
||||||
|
free(strichlisten[idx]);
|
||||||
|
strichlisten[idx] = neu;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ausgabe
|
||||||
|
for (int i = 0; i < NUM_DIGITS; ++i) {
|
||||||
|
printf("%d: %d %s\n", i, counts[i], strichlisten[i]);
|
||||||
|
free(strichlisten[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
BIN
wochentag.exe
BIN
wochentag.exe
Binary file not shown.
BIN
wortlen.exe
BIN
wortlen.exe
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user