+ 2
Is this really a language-specific algorithm? Here's a function that compares two strings and returns true if the second is a suffix of the first. I've added it to my code library if you want to play around with it. bool is_suffix(const std::string& input, const std::string& suffix) { // We can trivially reject if the suffix is longer than the input string. if (suffix.length() > input.length()) return false; // Compare the suffix to the end of the input string. string::compare returns 0 if the strings are equal. return input.compare(input.length() - suffix.length(), suffix.length(), suffix) == 0; } I'll leave actually reading the input from the user as an exercise.
26th Mar 2017, 7:32 PM
Squidy - avatar