Last active
February 26, 2020 02:16
-
-
Save chrisjurich/d72d7d815629a552896e121d59e55d54 to your computer and use it in GitHub Desktop.
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 <map> | |
bool | |
is_num(std::string& string_token, std::set<char>& accepted_characters){ | |
auto accepted_chars = std::map<char,int>(); | |
for(const auto& character : string_token) { | |
if(accepted_characters.find(character) == accepted_characters.end()) { | |
if(character < '0' or character > '9') { | |
accepted_chars[character]++; | |
} | |
} | |
} | |
for(const auto& char_count_pairs : accepted_chars) { | |
if(char_count_pairs.second > 1) { | |
return false; | |
} | |
} | |
return true; | |
} | |
int | |
main() { | |
/* for this function, you need to make a set of characters to compare the strings against */ | |
auto holder = std::string("0123456789.-Ee"); | |
auto accepted_char_set = std::set<char>(); | |
for(auto& ch : holder) { | |
accepted_char_set.insert(ch); | |
} | |
/* this is where you call the function using the set of characters as well as | |
* the token string | |
* */ | |
auto demo = std::string("demo"); | |
is_num(demo, accepted_char_set); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment