Skip to content

Instantly share code, notes, and snippets.

@tahmidsadik
Last active May 24, 2019 06:57
Show Gist options
  • Save tahmidsadik/4d08a8a7b2c02e30806fe54073c7b5e4 to your computer and use it in GitHub Desktop.
Save tahmidsadik/4d08a8a7b2c02e30806fe54073c7b5e4 to your computer and use it in GitHub Desktop.
Deduplicating numbers in C++
#include <iostream>
int main()
{
int number_counts[100] = { 0 }; // initializing an array of 100 elements with all of their value set to zero
int input_nums[] = { 1, 4, 6, 3, 9, 6, 7, 2, 3, 6, 8, 7, 3, 5, 6 }; // the input array
// looping over the input array and incrementing the count of an input
for (int i: input_nums) {
number_counts[i] = number_counts[i] + 1;
}
// just printing stuff
std::cout << "Duplcate Values = ";
for (int i = 0; i < 100; i++) {
if (number_counts[i] > 1) {
std::cout << i << ", ";
}
}
std::cout << std::endl;
// more printing
std::cout << "Non Duplicate Values = ";
for (int i = 0; i < 100; i++) {
if (number_counts[i] == 1) {
std::cout << i << ", ";
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment