[Codewars] Greed is Good

Greed is Good

  • Time :
  • Space :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <bits/stdc++.h>
using namespace std;
int score(const std::vector<int>& dice) {
unordered_map<int, int> freq;
int res = 0;
for(auto d : dice) {
if(++freq[d] == 3) {
freq[d] = 0;
if(d == 1) res += 1000;
else res += d * 100;
}
}
res += 100 * freq[1];
res += 50 * freq[5];
return res;
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2023/04/30/PS/Codewars/greed-is-good/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.