閉店前に、パン屋さんは明日多めに焼けるよう、売り切れそうなものを確認します。残りが 3 個未満の名前を、アルファベット順(map がもともと並べている順)で vector にして返す low_stock(stock) を書きましょう。
low_stock({{"bun", 5}, {"pie", 2}, {"cake", 0}})→['cake', 'pie']low_stock({{"tart", 4}})→[]vector<string> low_stock(const map<string, int> &stock)#include <map>
#include <string>
#include <vector>
using namespace std;
vector<string> low_stock(const map<string, int> &stock) {
vector<string> names;
for (const auto &item : stock) {
// ここにコードを書く:残りが 3 個未満なら名前を names に入れる
}
return names;
}
実行すると例で試せます。よさそうなら提出しましょう。