#include #include #include #include int soucet; int pocet; typedef struct _Ucet { char cislo[11]; int castka; struct _Ucet *next; struct _Ucet *onext; } Ucet; Ucet *ucet_new() { Ucet *u; u=(Ucet*)malloc(sizeof(Ucet)); u->next=0; u->onext=0; memset(u->cislo,0,11); return u; } void ucet_free(Ucet *u) { free(u); } #define HT_SIZE 1000 int key(char *cislo) { int i; int k=0; for (i=0;i<5;i++) { k=k^((unsigned short*)cislo)[i]; } return k%HT_SIZE; } Ucet *ht[HT_SIZE]; Ucet *ofirst, **olast; void htadd(Ucet *u) { Ucet *h; int k=key(u->cislo); h=ht[k]; u->next=h; ht[k]=u; (*olast)=u; olast=&(u->onext); } Ucet *htget(char *cislo) { int k=key(cislo); Ucet *h=ht[k]; while (h && strcmp(h->cislo,cislo)) h=h->next; return h; } void htreset() { int i; Ucet *h, *o; for (i=0;inext; ucet_free(o); } ht[i]=0; ofirst=0; olast=&ofirst; } } char s[200]; char x[11]; char y[11]; int ca,cb; int cas; Ucet *u,*u2; int main() { int i; int fail; for (i=0;icastka=0; strcpy(u->cislo,x); pocet++; htadd(u); printf("Ucet %s vytvoren.\n\n",x); } } else if (!strcmp("LIST",s)) { u=ofirst; printf("Pocet uctu: %d\n",pocet); while (u) { printf("%s %7d.%02d\n",u->cislo,(u->castka)/100,(u->castka)%100); u=u->onext; } printf("Celkem: %7d.%02d\n\n",soucet/100,soucet%100); } else if (!strcmp("STATISTIKA",s)) { u=ofirst; printf("Pocet uctu: %d\n",pocet); printf("Celkem: %7d.%02d\n\n",soucet/100,soucet%100); } else if (!strcmp("RESET",s)) { htreset(); pocet=0; soucet=0; printf("Reset systemu.\n\n"); } else if (!strcmp("ULOZ",s)) { scanf("%s",x); scanf("%d.%d",&ca,&cb); cas=cb+100*ca; if (!(u=htget(x))) printf("Ucet %s neexistuje.\n\n",x); else { u->castka+=cas; soucet+=cas; printf("Ulozeno %d.%02d na ucet %s.\n\n",ca,cb,x); } } else if (!strcmp("VYBER",s)) { scanf("%s",x); scanf("%d.%d",&ca,&cb); cas=cb+100*ca; if (!(u=htget(x))) printf("Ucet %s neexistuje.\n\n",x); else { if (u->castkacastka-=cas; soucet-=cas; printf("Vybrano %d.%02d z uctu %s.\n\n",ca,cb,x); } } } else if (!strcmp("PREVED",s)) { scanf("%s",x); scanf("%s",y); scanf("%d.%d",&ca,&cb); cas=cb+100*ca; fail=0; if (!(u=htget(x))) { printf("Ucet %s neexistuje.\n\n",x); fail=1; } else if (u->castkacastka+=cas; u->castka-=cas; printf("Prevedeno %d.%02d z uctu %s na ucet %s.\n\n",ca,cb,x,y); } } } printf("Konec.\n"); return 0; }