Question 20
Back to Exercise
What is the output of the following C++ program on a 64-bit system?
#include <iostream>
#include <string>
bool is_rotation(const std::string& a, const std::string& b) {
return a.size() == b.size() && (a + a).find(b) != std::string::npos;
}
int main() {
std::cout << is_rotation("waterbottle", "erbottlewat")
<< is_rotation("abcd", "acbd")
<< is_rotation("aa", "a")
<< is_rotation("", "") << '\n';
return 0;
}
- A 1001 Correct
- B 1000
- C 1011
- D 1101
Correct Answer: Option A
Every rotation of a appears inside a + a. "acbd" is a permutation but not a rotation; "aa" and "a" differ in length; two empty strings count as rotations of each other.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!