#include #include #include #include #include using namespace std; map acc; int someacc = -1; char res[1000 * 60]; char num[10]; int poc; int rand1() { return rand() % 10; } int makenew(int bank = -1) { int i; int res = 0; do { res = 0; for (i = 0; i < (bank > -1 ? 4 : 5); i++) res = res * 10 + rand1(); if (bank > -1) res = res * 10 + bank; //printf("%d\n", res); } while (acc.count(res) > 0); acc[res] = 0; poc++; if (someacc == -1) someacc = res; return res; } int makeone() { if (someacc == -1) return makenew(); else return someacc; } void strch(char * str, int c) { int len = strlen(str); str[len] = (char)c; str[len+1] = 0; } void insertacc(int acc, char *c) { int i, j; j = 10000; for (i = 0; i < 4; i++) { strch(c, ((acc / j)%10) + 48); j /= 10; } strch(c, '/'); strch(c, (acc % 10) + 48); } void writeln() { strcat(res, "\n"); } char * ftos(double d) { sprintf(num, "%.2lf", d); return num; } char * aftercolon(char * str) { return strchr(str, ':') + 2; } int main() { int i, j, a, b; char line[500]; char sth[100]; double bal; fgets(line, 400, stdin); res[0] = 0; poc = 0; while (strncmp(line, "goodbye", 7) != 0) { //printf(".%s.\n", line); if (strchr(line, ':') != NULL && strncmp(aftercolon(line), "no such", 7) == 0) { b = strchr(line, ' ') - line; strncat(res, line, b + 1); sscanf(line + b, "%lf", &bal); a = makenew(); acc[a] = -1; poc--; //printf("here %s\n", line); insertacc(a, res); if (line[0] == 't') { strcat(res, " "); insertacc(makeone(), res); } strcat(res, " "); strcat(res, ftos(bal)); writeln(); } else { if (strncmp(line, "create", 6) == 0) { strcat(res, "create "); if (strncmp(line + 8, "ok", 2) == 0) { a = makenew(); insertacc(a, res); acc[a] = -1; poc--; } else insertacc(makeone(), res); writeln(); } else if (strncmp(line, "deposit", 7) == 0) { strcat(res, "deposit "); sscanf(line + 8, "%lf", &bal); //printf("poc = %d\n", poc); insertacc(makeone(), res); //printf("poc = %d\n", poc); strcat(res, " "); strcat(res, ftos(bal)); writeln(); } else if (strncmp(line, "withdraw", 8) == 0) { // printf("here\n"); strcat(res, "withdraw "); sscanf(line + 9, "%lf", &bal); a = makenew(); if (strncmp(aftercolon(line), "insuf", 5) == 0) acc[a] = 0; else acc[a] = bal; insertacc(a, res); strcat(res, " "); strcat(res, ftos(bal)); writeln(); } else if (strncmp(line, "transfer", 8) == 0) { strcat(res, "transfer "); sscanf(line + 9, "%lf", &bal); if (strncmp(aftercolon(line), "same", 4) == 0) a = b = makeone(); else if (strncmp(aftercolon(line), "insuf", 5) == 0) { a = makenew(); b = makeone(); acc[a] = 0; } else if (strncmp(aftercolon(line), "inter", 5) == 0) { a = makeone(); b = makenew(((a % 10) + 1) % 10); } else { a = makenew(); b = makeone(); acc[a] = bal; } insertacc(a, res); strcat(res, " "); insertacc(b, res); strcat(res, " "); strcat(res, ftos(bal)); writeln(); } else if (strncmp(line, "end", 3) == 0) { if (poc == 0) { makenew(); } //printf("eeeeeeeeend\n"); strcat(res, "end\n\n"); printf("%d\n", poc); //printf("here---end\n"); map::iterator iter; for (iter = acc.begin(); iter != acc.end(); iter++) { if (iter->second >= 0) { sth[0] = 0; insertacc(iter->first, sth); printf("%s %.2lf\n", sth, iter->second); } } printf("%s", res); res[0] = 0; poc = 0; someacc = -1; acc.clear(); } } //printf("koniec"); fgets(line, 400, stdin); } printf("0\n"); return 0; }