#include #include int main(void) { char line[1024]; int accounts; int acc[2000][2]; int suma[2000][2]; int x, y; int x2, y2; int xx, yy; int n; int found, found2, i, j; while (1) { fgets(line, sizeof(line), stdin); line[strlen(line)-1] = '\0'; accounts = atoi(line); if (accounts == 0) break; memset(acc, 0, sizeof(acc)); n = 0; while (1) { fgets(line, sizeof(line), stdin); line[strlen(line)-1] = '\0'; if (!strcmp(line, "end")) break; if (!strncmp(line, "create", strlen("create"))) { sscanf(line, "create %d/%d", &x, &y); found = 0; for (i = 0; i < n; i++) { if (acc[i][0] == x && acc[i][1] == y) { found = 1; break; } } if (found) printf("create: already exists\n"); else { printf("create: ok\n"); acc[n][0] = x; acc[n][1] = y; suma[n][0] = 0; suma[n][1] = 0; n++; } } else if (!strncmp(line, "withdraw", strlen("withdraw"))) { sscanf(line, "withdraw %d/%d %d.%d", &x, &y, &xx, &yy); found = 0; for (i = 0; i < n; i++) { if (acc[i][0] == x && acc[i][1] == y) { found = 1; break; } } if (!found) printf("withdraw %d.%02d: no such account\n", xx, yy); else { if (suma[i][0] < xx || (suma[i][0] == xx && suma[i][1] < yy)) printf("withdraw %d.%02d: insufficient funds\n", xx, yy); else { printf("withdraw %d.%02d: ok\n", xx, yy); suma[i][0] -= xx; suma[i][1] -= yy; if (suma[i][1] < 0) { suma[i][1] += 100; suma[i][0] -= 1; } } } } else if (!strncmp(line, "deposit", strlen("deposit"))) { sscanf(line, "deposit %d/%d %d.%d", &x, &y, &xx, &yy); found = 0; for (i = 0; i < n; i++) { if (acc[i][0] == x && acc[i][1] == y) { found = 1; break; } } if (!found) printf("deposit %d.%02d: no such account\n", xx , yy); else { printf("deposit %d.%02d: ok\n", xx, yy); suma[i][0] += xx; suma[i][1] += yy; if (suma[i][1] >= 100) { suma[i][1] -= 100; suma[i][0] += 1; } } } else if (!strncmp(line, "transfer", strlen("transfer"))) { sscanf(line, "transfer %d/%d %d/%d %d.%d", &x, &y, &x2, &y2, &xx, &yy); found = 0; for (i = 0; i < n; i++) { if (acc[i][0] == x && acc[i][1] == y) { found = 1; break; } } found2 = 0; for (j = 0; j < n; j++) { if (acc[j][0] == x2 && acc[j][1] == y2) { found2 = 1; break; } } if (!found || !found2) printf("transfer %d.%02d: no such account\n", xx, yy); else { if (i == j) { printf("transfer %d.%02d: same account\n", xx, yy); } else { if (suma[i][0] < xx || (suma[i][0] == xx && suma[i][1] < yy)) printf("transfer %d.%02d: insufficient funds\n", xx, yy); else { if (acc[i][1] == acc[j][1]) printf("transfer %d.%02d: ok\n", xx, yy); else printf("transfer %d.%02d: interbank\n", xx, yy); suma[i][0] -= xx; suma[i][1] -= yy; suma[j][0] += xx; suma[j][1] += yy; if (suma[i][1] < 0) { suma[i][1] += 100; suma[i][0] -= 1; } if (suma[j][1] >= 100) { suma[j][1] -= 100; suma[j][0] += 1; } } } } } else { sscanf(line, "%d/%d %d.%d", &x, &y, &xx, &yy); acc[n][0] = x; acc[n][1] = y; suma[n][0] = xx; suma[n][1] = yy; n++; } } fgets(line, sizeof(line), stdin); printf("end\n\n"); } printf("goodbye\n"); return 0; }