#include #define END "end" #define ZERO "0" #define TRANSFER "transfer" #define DEPOSIT "deposit" #define WITHDRAW "withdraw" #define CREATE "create" typedef char STRING[255]; typedef struct _SU { char c[10]; double z; } SU; int A, i, j, index, index2; SU U[1000]; double s; STRING pc1, pc2, p, ss; int load() { int i; scanf("%d", &A); if (!A) return 0; for (i = 0; i < A; i++) { scanf("%s %s", U[i].c, ss); sscanf(ss, "%lf", &U[i].z); } return 1; } int main () { load(); while (1 == 1) { strcpy(p, ""); scanf("%s" , p); if (!strcmp(p, END)) { printf("%s\n\n", END); if (!load()) break; continue; } scanf("%s", pc1); if (!strcmp(p, TRANSFER)) { scanf("%s", pc2); } if (strcmp(p, CREATE) != 0) { scanf("%s", ss); sscanf(ss, "%lf", &s); } /*************************/ for (i = 0, index = -1; i < A; i++) { if (!strcmp(U[i].c, pc1)) { index = i; break; } } if (!strcmp(p, TRANSFER)) { for (j = 0, index2 = -1; j < A; j++) { if (!strcmp(U[j].c, pc2)) { index2 = j; break; } } printf("%s %.2lf: ", TRANSFER, s); if ( (index != -1) && (index2 != -1) ) { if (!strcmp(pc1, pc2)) { printf("same account\n"); continue; } if (U[index].z < s) { printf("insufficient funds\n"); continue; } if (pc1[5] != pc2[5]) { printf("interbank\n"); } else printf("ok\n"); U[index].z -= s; U[index2].z += s; } else { printf("no such account\n"); } } if (!strcmp(p, CREATE)) { printf("%s: ", CREATE); if (index != -1) { printf("already exists\n"); continue; } printf("ok\n"); strcpy(U[A++].c, pc1); U[A].z = 0; } if (!strcmp(p, DEPOSIT)) { printf("%s %.2lf: ", DEPOSIT, s); if (index != -1) { U[index].z += s; printf("ok\n"); continue; } printf("no such account\n"); } if (!strcmp(p, WITHDRAW)) { printf("%s %.2lf: ", WITHDRAW, s); if (index != -1) { if (U[index].z < s) { printf("insufficient funds\n"); continue; } U[index].z -= s; printf("ok\n"); } else { printf("no such account\n"); } } /*********************************/ } printf("goodbye\n"); return 0; }