Kodewick
学びはじめる →
ミニチャレンジ←→0 / 60

一番人気

#031ミニチャレンジcount[drink]++約 7 分

お茶屋さんでは、売れた飲み物の名前を 1 杯ずつ記録しています。一番多く売れた飲み物を返す best_seller(sales) を書きましょう。同じ数なら、アルファベット順で先のものを返します。少なくとも 1 杯は売れています。

例
best_seller({"latte", "tea", "latte"})→'latte'
best_seller({"mocha"})→'mocha'
関数string best_seller(const vector<string> &sales)
main.cpp
#include <map>
#include <string>
#include <vector>
using namespace std;

string best_seller(const vector<string> &sales) {
    map<string, int> count;
    for (const string &drink : sales) {
        // ここにコードを書く:この飲み物の数に 1 を足す
    }
    string best = "";
    int most = 0;
    for (const auto &item : count) {
        // ここにコードを書く:most を超えたら、この飲み物とその数を覚える
    }
    return best;
}
Ctrl + Enter でも実行できます
結果

実行すると例で試せます。よさそうなら提出しましょう。