thbenisa
BAN USERmap<string, int> StoreElectronicsInfo(string str_array[], int len) {
// "/Electronics/Computers/Graphics Cards"
map<string, int> dict;
string word;
for(int i=0; i < len; i++) {
// Travarse each string in array
for(int j=0; j < str_array[i].size(); j++) {
// Add chars to word string
word += str_array[i][j];
// Check for '/' and end of string
if( str_array[i][j] == '/' || j == str_array[i].size() - 1 ) {
// First '/'
if(word.size() == 1) {
dict[word]++; // Add '/' word and increment word count in map
}
else if(word.back() == '/') {
word.resize(word.size() - 1); // Remove last '/' from word, before adding it to map
}
dict[word]++; // Increment string count (minues last '/') to map
word += '/'; // Add '/' back to word
//cout << word << " = " << dict[word] << endl;
}
}
word = ""; // Erase word
}
return dict;
}
map<string, int> StoreElectronicsInfo(string str_array[], int len) {
// "/Electronics/Computers/Graphics Cards"
map<string, int> dict;
string word;
for(int i=0; i < len; i++) {
// Travarse each string in array
for(int j=0; j < str_array[i].size(); j++) {
// Add chars to word string
word += str_array[i][j];
// Check for '/' and end of string
if( str_array[i][j] == '/' || j == str_array[i].size() - 1 ) {
if(word.size() == 1) {
dict[word]++; // First '/'. Add '/' word and increment word count in map
}
else if(word.back() == '/') {
word.resize(word.size() - 1); // Remove last '/' from word, before adding it to map
}
dict[word]++; // Increment string count (minus last '/') to map
word += '/'; // Add '/' back to word
}
}
word = ""; // Erase word
}
return dict;
}
map<string, int> StoreElectroncisInfo(string str_array[], int len) {
map<string, int> dict;
string word;
for(int i=0; i < len; i++) {
for(int j=0; j < str_array[i].size(); j++) {
word += str_array[i][j];
if( str_array[i][j] == '/' || j == str_array[i].size()-1 ) {
int back = word.back();
if(word.size() == 1) {
dict[word]++;
}
else if(back == '/') {
word.resize(word.size()-1);
}
dict[word]++;
word += '/';
//cout << word << " = " << dict[word] << endl;
}
}
word = "";
}
return dict;
}
- thbenisa September 09, 2023