문제 원문 :
Determine whether the given string can be obtained by one concatenation of some string to itself.
주어진 문자열을 반으로 나누었을때 같다면 참, 아니면 거짓을 반환합니다.
문제 예시 :
- For inputString = "tandemtandem", the output should be
isTandemRepeat(inputString) = true; - For inputString = "qqq", the output should be
isTandemRepeat(inputString) = false; - For inputString = "2w2ww", the output should be
isTandemRepeat(inputString) = false.
코드 풀이 :
bool isTandemRepeat(std::string inputString)
{
if (inputString.size() % 2 == 1) return false;
string A, B;
A = inputString.substr(0, inputString.size() / 2);
B = inputString.substr(inputString.size() / 2, inputString.size());
return A == B;
}