Keresés

Új hozzászólás Aktív témák

  • _lupin_

    csendes tag

    válasz cybear #42 üzenetére

    Szia!

    Azt nem mondtad, hogy a megoldáshoz mit szabad használni és mit nem, ezért eléggé támaszkodtam az stl-re.


    #include <map>
    #include <algorithm>
    #include <iostream>
    #include <string>

    typedef std::pair<std::string, int> MapMember;
    bool compare(const MapMember& larg, const MapMember& rarg)
    {
    return larg.second < rarg.second;
    }

    int main()
    {
    std::map<std::string, int> votes;
    std::string name;

    std::cout << ''Kerem a nevet: '';
    std::getline(std::cin, name);
    while( name != '''' )
    {
    if(votes.find(name) != votes.end()) ++votes[name];
    else votes[name] = 1;

    std::cout << ''Kerem a nevet: '';
    std::getline(std::cin, name);
    }
    std::cout << std::endl;

    std::map<std::string, int>::iterator it;
    int i = 1;

    while( (votes.size() > 0) && (i <= 3))
    {
    it = max_element(votes.begin(), votes.end(), compare);
    std::cout << i << ''. '' << it->first << '' szavazat: '' << it->second << std::endl;
    votes.erase(it);
    ++i;
    }

    return 0;
    }


    szerk:
    Próbáltam rávenni, hogy amit kell beljebb írja, de nem hajlandó...

    [Szerkesztve]

    -Egyszer ez mind a téd lesz fiam! -A függöny?

Új hozzászólás Aktív témák