Kodewick
开始学 →
小挑战←→0 / 60

跳绳奖牌

#058小挑战map循环约 6 分钟

跳绳比赛,skips 是每个人一分钟跳了几下。100 下及以上拿 "gold",80 及以上拿 "silver",60 及以上拿 "bronze",不到 60 没有奖牌。写循环里面,数每种奖牌发了几块;没人拿的奖牌不出现在结果里。

示例
medals({120, 85, 61, 30})→{'bronze': 1, 'gold': 1, 'silver': 1}
medals({})→{}
函数map<string, int> medals(const vector<int> &skips)
main.cpp
#include <map>
#include <string>
#include <vector>
using namespace std;

map<string, int> medals(const vector<int> &skips) {
    map<string, int> count;
    for (int s : skips) {
        // 在这里写:看 s 拿哪种奖牌,那种加 1
    }
    return count;
}
Ctrl + Enter 也能运行
结果

写好了先点「运行」试试示例,没问题再点「提交」。