お茶屋さんでは、売れた飲み物の名前を 1 杯ずつ記録しています。一番多く売れた飲み物を返す best_seller(sales) を書きましょう。同じ数なら、アルファベット順で先のものを返します。少なくとも 1 杯は売れています。
best_seller({"latte", "tea", "latte"})→'latte'best_seller({"mocha"})→'mocha'string best_seller(const vector<string> &sales)#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;
}
実行すると例で試せます。よさそうなら提出しましょう。