diff options
author | crupest <crupest@outlook.com> | 2021-11-19 11:57:35 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2021-11-19 11:57:35 +0800 |
commit | 205f243379919b7830726f9dcc4ae7d33c84e857 (patch) | |
tree | b18b433bcd9d1d9bb38e6da18c880f8fddb1cea9 /works/life/algorithm-experiment/5.2b.cpp | |
parent | 3c9273676b785c6ba4fc11e865851ba2319f41bf (diff) | |
download | crupest-205f243379919b7830726f9dcc4ae7d33c84e857.tar.gz crupest-205f243379919b7830726f9dcc4ae7d33c84e857.tar.bz2 crupest-205f243379919b7830726f9dcc4ae7d33c84e857.zip |
import(life): Add algorithm experiment 5.
Diffstat (limited to 'works/life/algorithm-experiment/5.2b.cpp')
-rw-r--r-- | works/life/algorithm-experiment/5.2b.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/works/life/algorithm-experiment/5.2b.cpp b/works/life/algorithm-experiment/5.2b.cpp new file mode 100644 index 0000000..d062ae0 --- /dev/null +++ b/works/life/algorithm-experiment/5.2b.cpp @@ -0,0 +1,28 @@ +#include <iostream> +#include <unordered_map> +#include <vector> + +int main() { + std::vector<long long> votes; + + long long v; + while (std::cin >> v) { + votes.push_back(v); + } + + std::unordered_map<long long, long long> counts; + for (auto v : votes) { + counts[v]++; + } + + // Get ids with votes greater than half of the total votes. + long long half_votes = votes.size() / 2; + + for (auto it = counts.begin(); it != counts.end(); ++it) { + if (it->second > half_votes) { + std::cout << it->first << std::endl; + } + } + + return 0; +} |