Last active
August 29, 2015 14:09
-
-
Save zimuliu/9820d110a10d264726ac to your computer and use it in GitHub Desktop.
countUnique
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> | |
#include <set> | |
#include <vector> | |
int countUnique(const std::vector<std::string> &a) { | |
std::set<std::string> uniqueStrings; | |
for (std::vector<std::string>::const_iterator itr = a.begin(); itr != a.end(); itr++) { | |
if (uniqueStrings.end() == uniqueStrings.find(*itr)) { | |
uniqueStrings.insert(*itr); | |
} | |
} | |
return uniqueStrings.size(); | |
} | |
int main(int argc, char *argv[]) { | |
std::vector<std::string> test; | |
test.push_back("zsddf"); | |
test.push_back("zsd"); | |
test.push_back("zsddf"); | |
test.push_back("zsd"); | |
test.push_back("z"); | |
std::cout << countUnique(test); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment