#include #include #include #include using namespace std; struct ucet{ string cisloUctu; char kodBanky; int zustatek; }; float round(float f) { int i = (int)(f * 1000); int m = i%10; i = i-m; if (m >= 5) { return (float) (i+10) / 1000;} return (float) i / 1000; } float toF(int x) { return ((float) x) / 100; } int toI(float x) { int a = (int) (round(x * 100)); return a; } ucet* findUcet(vector& ucty, string& number) { for (unsigned i = 0; i& ucty){ string cisloUctu; cin >> cisloUctu; if (findUcet(ucty,cisloUctu)) { cout << "create: already exists" << endl; return; } ucet u; u.cisloUctu = cisloUctu; u.kodBanky = u.cisloUctu[u.cisloUctu.length()-1]; u.zustatek = 0; ucty.push_back(u); cout << "create: ok" << endl; } void deposit(vector& ucty) { string cisloUctu; cin >> cisloUctu; float pF; cin >> pF; int p = toI(pF); ucet * u = findUcet(ucty, cisloUctu); if (u) { u->zustatek += p; cout << "deposit "; printf("%.2f",toF(p)); cout << ": ok" << endl; return; } cout << "deposit "; printf("%.2f",toF(p)); cout << ": no such account" << endl; } void withdraw(vector& ucty){ string cisloUctu; cin >> cisloUctu; float pF; cin >> pF; int p = toI(pF); ucet * u = findUcet(ucty, cisloUctu); if (u) { if(p <= u -> zustatek){ u->zustatek -= p; cout << "withdraw "; printf("%.2f",toF(p)); cout << ": ok" << endl; }else{ cout << "withdraw "; printf("%.2f",toF(p)); cout << ": insufficient funds" << endl; } return; } cout << "withdraw "; printf("%.2f",toF(p)); cout << ": no such account" << endl; } void transfer(vector& ucty){ string src, dest; cin >> src; cin >> dest; ucet *srcUcet = NULL; ucet *destUcet = NULL; float pF; cin >> pF; int p = toI(pF); srcUcet = findUcet(ucty,src); destUcet = findUcet(ucty,dest); if(!srcUcet || !destUcet){ cout << "transfer "; printf("%.2f",toF(p)); cout << ": no such account" << endl; return; } if(src == dest){ cout << "transfer "; printf("%.2f",toF(p)); cout << ": same account" << endl; } else { if(srcUcet->zustatek < p){ cout << "transfer "; printf("%.2f",toF(p)); cout << ": insufficient funds" << endl; return; } srcUcet->zustatek -= p; destUcet->zustatek += p; if(srcUcet->kodBanky == destUcet->kodBanky){ cout << "transfer "; printf("%.2f",toF(p)); cout << ": ok" << endl; }else{ cout << "transfer "; printf("%.2f",toF(p)); cout << ": interbank" << endl; } } } int main () { while(true){ // nacitani uctu int pocetUctu; string operace; vector ucty; // nacteni uctu cin >> pocetUctu; if( pocetUctu == 0 ){ break; } for(int i = 0; i < pocetUctu; i++){ ucet u; cin >> u.cisloUctu; u.kodBanky = u.cisloUctu[u.cisloUctu.length()-1]; float p; cin >> p; u.zustatek = toI(p); ucty.push_back(u); } // operace while(true){ cin >> operace; if(operace == "end") break; if(operace == "create"){ create(ucty); }else if(operace == "deposit"){ deposit(ucty); }else if(operace == "withdraw"){ withdraw(ucty); }else if(operace == "transfer"){ transfer(ucty); } /*cout << "zustatek "; printf("%0.2f",toF(ucty[0].zustatek)); cout << endl;*/ } cout << "end" << endl; cout << endl; } cout << "goodbye" << endl; return 0; }