#include #include #include #include using namespace std; struct Agent { string name; double price; string action; Agent(string n, double p, string a = "") { name = n; price = p; action = a; } }; bool cmp(Agent a, Agent b) { return (a.price <= b.price); } int main() { string no_one = " NO-ONE"; int count; string name, action, agent; double price; vector buyers, sellers, all; while(1) { all.clear(); sellers.clear(); buyers.clear(); // HLAVA cin >> count >> name; if(count == 0 && name == "END") break; for(int i = 0; i < count; ++i) { cin >> agent; cin >> action; cin >> price; all.push_back(Agent(agent, price, action)); if(action == "buy") buyers.push_back(Agent(agent, price, action)); else sellers.push_back(Agent(agent, price, action)); } sort(buyers.begin(), buyers.end(), cmp); sort(sellers.begin(), sellers.end(), cmp); // vypis cout << name << endl; for(int i = 0; i < all.size(); ++i) { cout << all[i].name << ":"; if(all[i].action == "buy") { int j = 0; while(j < sellers.size()) { if(sellers[j].price > all[i].price) break; cout << " " << sellers[j].name; j++; } if(j == 0) cout << no_one; cout << endl; } else { int j = buyers.size() - 1; while(j >= 0) { if(buyers[j].price < all[i].price) break; cout << " " << buyers[j].name; j--; } if(j == buyers.size() - 1) cout << no_one; cout << endl; } } } return 0; }