Codesignal
<Codesignal> Is Tandem Repeat?
우현짱짱
2020. 4. 19. 15:52
Easy
Determine whether the given string can be obtained by one concatenation of some string to itself.
Example
- 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.
Input/Output
-
[execution time limit] 0.5 seconds (c)
-
[input] string inputString
Guaranteed constraints:
2 ≤ inputString.length ≤ 20. -
[output] boolean
- true if inputString represents a string concatenated to itself, false otherwise.
[C] Syntax Tips
// Prints help message to the console
// Returns a string
char * helloWorld(char * name) {
char * answer = malloc(strlen(name) + 8);
printf("This prints to the console when you Run Tests");
strcpy(answer, "Hello, ");
strcat(answer, name);
return answer;
}
더보기
Solution
bool isTandemRepeat(char *inputString)
{
for(int i=0;i<strlen(inputString)/2;i++)
if(inputString[i]!=inputString[strlen(inputString)/2+i])
return false;
return strlen(inputString)%2==0;
}
728x90