0

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"; }

3rd Dec 2022, 1:21 PM
The_Fox
The_Fox - avatar
4 Réponses
+ 4
Just wanna remind you to pay extra attention on the required output formatting. I seen someone failed it for one different letter case, so, careful with the outputs.
3rd Dec 2022, 3:07 PM
Ipang
+ 1
Is that the exact code of your solution? If it is, you hard coded the case instead of taking inputs. Btw, please check letter case like Ipang said.
3rd Dec 2022, 5:03 PM
Lochard
Lochard - avatar
+ 1
I didn't try the challenge. But this approach which is very different to yours should work with 4 inputs. Just for your reference. https://code.sololearn.com/chis40AWH5Ex/?ref=app
3rd Dec 2022, 5:14 PM
Lochard
Lochard - avatar
0
This is not the exact code, of course (no input). Just for demonstration purposes. Thank you both! I will check. By the way, I did use Open and Trash respectively… so there shouldn‘t be an issue with the output…
3rd Dec 2022, 5:06 PM
The_Fox
The_Fox - avatar