Created
December 6, 2021 02:40
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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