#include #include #include #include using namespace std; struct ucet{ string cisloUctu; char kodBanky; int zustatek; }; float toF(int x) { return ((float) x) / 100000; } int toI(float x) { return (int) (x * 100000); } float round(float f) { int i = f * 1000; int m = i%10; i = i-m; if (m >= 5) { return (float) (i+10) / 1000;} return (float) i / 1000; } void create(vector& ucty){ string cisloUctu; cin >> cisloUctu; for(unsigned i = 0; i< ucty.size(); i++){ if(ucty[i].cisloUctu == 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); for(unsigned i = 0; i< ucty.size(); i++){ if(ucty[i].cisloUctu == cisloUctu){ ucty[i].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); for(unsigned i = 0; i< ucty.size(); i++){ if(ucty[i].cisloUctu == cisloUctu){ if(p <= ucty[i].zustatek){ ucty[i].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); if(src == dest){ cout << "transfer "; printf("%.2f",toF(p)); cout << ": same account" << endl; }else{ for(unsigned i = 0; i< ucty.size(); i++){ if(ucty[i].cisloUctu == src){ srcUcet = &ucty[i]; } if(ucty[i].cisloUctu == dest){ destUcet = &ucty[i]; } } if(!srcUcet || !destUcet){ cout << "transfer "; printf("%.2f",toF(p)); cout << ": no such account" << endl; return; } 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(unsigned 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("%f",ucty[0].zustatek); cout << endl;*/ } cout << "end" << endl; cout << endl; } cout << "goodbye" << endl; return 0; }