Skip to content

Instantly share code, notes, and snippets.

@aeristhy
Created December 6, 2021 02:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aeristhy/c529e9601be18cd2f42e13330cf1ed95 to your computer and use it in GitHub Desktop.
Save aeristhy/c529e9601be18cd2f42e13330cf1ed95 to your computer and use it in GitHub Desktop.
Program that accepts 10 numbers and will then display and count the repeating numbers. (Array Exercises #3)
#include <unordered_map>
#include <vector>
#include <iostream>
using namespace std;
unordered_map<int, unsigned int> c(const vector<int> & x) {
unordered_map<int, unsigned int> z;
for (auto y : x) {
z[y]++;
}
return z;
}
void display(const unordered_map<int, unsigned int> & counts) {
for (auto count : counts) {
cout << count.first << " = " << count.second << ", ";
}
}
int main(int argc, char** argv) {
vector<int> array = { 1, 1, 9, 7, 8, 6, 4, 6, 6 };
display(c(array));
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment