#include #include #include #include using namespace std; ostringstream out; int parse_acctnum(string tmp){ int acctnum = 0; for(string::iterator it = tmp.begin(); it != tmp.end(); it++){ if(*it == '/') continue; acctnum *= 10; acctnum += (*it - '0'); } return acctnum; } int parse_amount(string tmp){ int amount = 0;; for(string::iterator it = tmp.begin(); it != tmp.end(); it++){ if(*it == '.' || *it == ':') continue; amount *= 10; amount += (*it - '0'); } return amount; } void format_amount(int a){ out << (a/100) << "." << ((a%100)/10) << (a%10); } int main(void) { map account; string tmp; int next = 1004; int start_accts = 2; while(true){ cin >> tmp; if(tmp == "create:"){ cin >> tmp; if(tmp == "ok"){ out << "create " << next << "/1" << endl; account.insert(make_pair((next*10)+1,-1)); next++; }else{ cin >> tmp; out << "create 1002/1\n"; } }else if(tmp == "deposit"){ cin >> tmp; int amount = parse_amount(tmp); cin >> tmp; if(tmp == "no"){ cin >> tmp; cin >> tmp; out << "deposit 1001/1 "; format_amount(amount); out << "\n"; }else{ out << "deposit 1002/1 "; format_amount(amount); out << "\n"; } }else if(tmp == "withdraw"){ cin >> tmp; int amount = parse_amount(tmp); cin >> tmp; if(tmp == "no"){ cin >> tmp; cin >> tmp; out << "withdraw 1001/1 "; format_amount(amount); out << "\n"; }else if(tmp == "insufficient"){ cin >> tmp; out << "withdraw 1003/1 "; format_amount(amount); out << "\n"; }else{ //ok account.insert(make_pair((next*10)+1,amount)); out << "withdraw " << next << "/1 "; format_amount(amount); out << "\n"; next++; start_accts++; } }else if(tmp == "transfer"){ cin >> tmp; int amount = parse_amount(tmp); cin >> tmp; if(tmp == "no"){ cin >> tmp; cin >> tmp; out << "transfer 1001/1 1002/1 "; format_amount(amount); out << "\n"; }else if(tmp == "ok"){ account.insert(make_pair((next*10)+1,amount)); start_accts++; out << "transfer " << next << "/1 1002/1 "; format_amount(amount); out << "\n"; next++; }else if(tmp == "interbank"){ account.insert(make_pair((next*10)+2,amount)); start_accts++; out << "transfer " << next << "/2 1002/1 "; format_amount(amount); out << "\n"; next++; }else if(tmp == "insufficient"){ cin >> tmp; out << "transfer 1003/1 1002/1 "; format_amount(amount); out << "\n"; }else if(tmp == "same"){ cin >> tmp; out << "transfer 1002/1 1002/1 "; format_amount(amount); out << "\n"; } }else if(tmp == "end"){ cout << start_accts << endl; for(map::const_iterator it = account.begin(); it != account.end(); it++){ if(it->second != -1){ cout << (it->first)/10 << "/" << (it->first)%10 << " "; cout << (it->second/100) << "." << ((it->second%100)/10) << (it->second%10); cout << "\n"; } } cout << "1002/1 0.00\n1003/1 0.00\n"; cout << out.str(); cout << "end\n\n"; start_accts = 2; next = 1004; account.erase(account.begin(), account.end()); out.str(""); //cout << "NOVYOUT:" << out.str() << "KONEC"; //vypsat, vycistit }else if(tmp == "goodbye"){ cout << endl << '0' << endl; break; } } return 0; }