Last active
May 24, 2019 06:57
-
-
Save tahmidsadik/4d08a8a7b2c02e30806fe54073c7b5e4 to your computer and use it in GitHub Desktop.
Deduplicating numbers in C++
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 <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