Hatena::Grouptopcoder

TopCoderの問題を解く

解いた問題の一覧表

2009-08-06

PartySeats

| 19:16

問題文 PartySeats

席順決め。

class PartySeats {
    public:
        vector <string> seating (vector <string> attendees) {
            multiset<string> boys, girls;
            for (int i = 0; i < attendees.size(); i++) {
                string name, gender;
                istringstream iss(attendees[i]);
                iss >> name >> gender;
                if (gender[0] == 'b') boys.insert(name);
                else girls.insert(name);
            }
            vector<string> result;
            if (boys.size() != girls.size() || boys.size()%2 == 1)
                return result;
            multiset<string>::const_iterator bItr = boys.begin();
            multiset<string>::const_iterator gItr = girls.begin();
            result.push_back("HOST");
            for (int i = 0; i < attendees.size()/2; i += 2) {
                result.push_back(*gItr); gItr++;
                result.push_back(*bItr); bItr++;
            }
            result.push_back("HOSTESS");
            for (int i = attendees.size()/2; i < attendees.size(); i += 2) {
                result.push_back(*bItr); bItr++;
                result.push_back(*gItr); gItr++;
            }
            return result;
        }
};

NathalieadsonNathalieadson2012/07/10 00:48Unparaellled accuracy, unequivocal clarity, and undeniable importance!

qumvofqumvof2012/07/10 15:55k9l8Kn <a href="http://ffbnrpylucxq.com/">ffbnrpylucxq</a>

kxvfpogrvtkxvfpogrvt2012/07/10 21:52DUrnSr , [url=http://odqnuvepnfcs.com/]odqnuvepnfcs[/url], [link=http://gllexsagvhok.com/]gllexsagvhok[/link], http://ctntvviqpnwt.com/

ahphkwegfjvahphkwegfjv2012/07/12 12:12jHPHB5 <a href="http://wujnvnxoozdt.com/">wujnvnxoozdt</a>