#include #include #include #include #include #define MAX_UCTU 10000 #define MAXUCET 2*MAX_UCTU+1023 #define DU 12 typedef struct { char jm[DU]; double zust; } sezn; sezn tabulka[MAXUCET]; int p_uctu[MAX_UCTU]; // cislo, pod kterym je to v tabulka int pocet_uctu=0; double celkem=0; inline int hash(char *klic) { int h=0; int i=1; while (*klic++) { h+=1023*(*klic)*i++; h%=MAXUCET; } return h; } // pokud uspeje, vrati 1, jinak 0 // zvysi pocet uctu v systemu inline int zaloz(char *ucet) { int h=hash(ucet); /* zalozeni */ // dokud tam neco je a neni to nas ucet while (strlen(tabulka[h].jm) && strcmp(tabulka[h].jm, ucet)) { h++; h%=MAXUCET; } if (strlen(tabulka[h].jm)) // je to nas ucet { return 0; } p_uctu[pocet_uctu]=h; pocet_uctu++; strcpy(tabulka[h].jm, ucet); tabulka[h].zust=0; return 1; } inline int find(char *ucet) { int h=hash(ucet); while (strlen(tabulka[h].jm) && strcmp(tabulka[h].jm, ucet)) { h++; h%=MAXUCET; } if (strlen(tabulka[h].jm)) // je to nas ucet { return h; } return 0; } // zjisti, zda ucet existuje inline int existuje(char *ucet) { return find(ucet); } // vrati zustatek u existujiciho uctu inline double zustatek(char *ucet) { if (int h=find(ucet)) { return tabulka[h].zust; } else return (double)-1; return -1; } // pokud uspeje, vrati 1, jinak 0 // pricte castku k celkovemu mnozstvi penez na uctech inline int uloz(char *ucet, double castka) { if (int h=find(ucet)) { tabulka[h].zust+=castka; celkem+=castka; return 1; } return 0; } inline int vyber(char *z, double castka) { if (int h=find(z)) { if (tabulka[h].zust>=castka) { tabulka[h].zust-=castka; celkem-=castka; return 1; } else return 0; } else return -1; } // reset systemu inline void reset_s() { celkem=0; for (int i=0;i=castka) { if (existuje(cislo_uctu2)) { vyber(cislo_uctu, castka); uloz(cislo_uctu2, castka); printf("Prevedeno %.2f z uctu %s na ucet %s.\n",castka, cislo_uctu, cislo_uctu2); } else { printf("Ucet %s neexistuje.\n", cislo_uctu2); } } else { printf("Nedostatek penez.\n"); if (!existuje(cislo_uctu2)) { printf("Ucet %s neexistuje.\n", cislo_uctu2); } } } else { printf("Ucet %s neexistuje.\n", cislo_uctu); if (!existuje(cislo_uctu2)) { printf("Ucet %s neexistuje.\n", cislo_uctu2); } } } if (!strcmp(prikaz,"STATISTIKA")){ printf("Pocet uctu: %d\n",pocet_uctu); printf("Celkem: % 10.2f\n", celkem); scanf("\n"); } if (!strcmp(prikaz,"LIST")){ printf("Pocet uctu: %d\n",pocet_uctu); scanf("\n"); for (int i=0;i