#include #include #include #define MAXN 16384 #define MAXH 16384 struct name { char v[11]; unsigned hash; }; void read_name (struct name *dest) { char *p; scanf ("%s", dest->v); dest->hash = 0; for (p = dest->v; *p != 0; p++) dest->hash = dest->hash * 10 + *p - '0'; dest->hash %= MAXH; } struct acct { struct acct *hn; char name[11]; long double val; }; struct acct accts[MAXN], *next_acct = accts; struct acct *hash[MAXH]; struct acct * find_acct (const struct name *name) { struct acct *p; for (p = hash[name->hash]; p != NULL; p = p->hn) if (strcmp (p->name, name->v) == 0) return p; return NULL; } long double total = 0.0L; int main (void) { for (;;) { char buf[15]; scanf (" "); if (feof (stdin)) break; if (scanf ("%s", buf) == 0) break; if (strcmp (buf, "ZALOZ") == 0) { struct name n; struct acct *a; read_name (&n); a = find_acct (&n); if (a != NULL) printf ("Ucet %s uz existuje.\n", n.v); else { struct acct **h; a = next_acct++; h = hash + n.hash; a->hn = *h; *h = a; memcpy (a->name, n.v, sizeof (a->name)); a->val = 0.0L; printf ("Ucet %s vytvoren.\n", n.v); } } else if (strcmp (buf, "ULOZ") == 0) { struct name n; struct acct *a; long double f; read_name (&n); scanf ("%Lf", &f); a = find_acct (&n); if (a == NULL) printf ("Ucet %s neexistuje.\n", n.v); else { a->val += f; total += f; printf ("Ulozeno %.02Lf na ucet %s.\n", f, n.v); } } else if (strcmp (buf, "VYBER") == 0) { struct name n; struct acct *a; long double f; read_name (&n); scanf ("%Lf", &f); a = find_acct (&n); if (a == NULL) printf ("Ucet %s neexistuje.\n", n.v); else { if (a->val < f) printf ("Nedostatek penez.\n"); else { a->val -= f; total -= f; printf ("Vybrano %.02Lf z uctu %s.\n", f, n.v); } } } else if (strcmp (buf, "PREVED") == 0) { struct name n1, n2; struct acct *a1, *a2; long double f; read_name (&n1); read_name (&n2); scanf ("%Lf", &f); a1 = find_acct (&n1); if (a1 == NULL) { printf ("Ucet %s neexistuje.\n", n1.v); goto err; } a2 = find_acct (&n2); if (a2 == NULL) { printf ("Ucet %s neexistuje.\n", n2.v); goto err; } if (a1->val < f) { printf ("Nedostatek penez.\n"); goto err; } a1->val -= f; a2->val += f; printf ("Prevedeno %.02Lf z uctu %s na ucet %s.\n", f, n1.v, n2.v); } else if (strcmp (buf, "STATISTIKA") == 0) { printf ("Pocet uctu: %u\n", next_acct - accts); printf ("Celkem: %10.02Lf\n", total); } else if (strcmp (buf, "LIST") == 0) { struct acct *a; printf ("Pocet uctu: %u\n", next_acct - accts); for (a = accts; a < next_acct; a++) printf ("%s %10.02Lf\n", a->name, a->val); printf ("Celkem: %10.02Lf\n", total); } else if (strcmp (buf, "RESET") == 0) { memset (accts, 0, (next_acct - accts) * sizeof (*accts)); next_acct = accts; memset (hash, 0, sizeof (hash)); total = 0.0L; printf ("Reset systemu.\n"); } err: printf ("\n"); } printf ("Konec.\n"); return EXIT_SUCCESS; }