c++ question on 'It's a sign' challenge
Hey there. I came up with a rather complicated solution (well, not really) to the "it's a sign" challenge. In two cases, the code does not quite work and I cannot think of why that is the case. Any help or hints would be happily appreciated. #include <iostream> #include <sstream> #include <string> #include <vector> #include <algorithm> int main() { std::string str = "CATS MONDYAS RACeCAR TACOS"; std::string str2(str.rbegin(), str.rend()); //reverse string items int count = 0; std::vector<std::string> vecStr; std::vector<std::string> vecStr2; std::stringstream ss(str); //convert str into stringstream std::stringstream ss2(str2); //convert str into stringstream std::string strTemp, strTemp2; while (ss >> strTemp) //optional with delimiter -> getline(ss, strTemp, ',') { vecStr.push_back(strTemp); } while (ss2 >> strTemp2) //optional with delimiter -> getline(ss, strTemp, ',') { vecStr2.push_back(strTemp2); } std::reverse(vecStr2.begin(), vecStr2.end()); //reset order of elements to original //comparing elements in two vectors for (std::size_t i = 0; i != vecStr.size(); i++) { if (vecStr[i] == vecStr2[i]) count++; } if (count != 0) std::cout << "OPEN"; else std::cout << "TRASH"; }