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

'Codesignal' 카테고리의 다른 글

<Codesignal> Find Email Domain  (0) 2020.04.19
<Codesignal> Is Case-Insensitive Palindrome?  (0) 2020.04.19
<Codesignal> Proper Noun Correction  (0) 2020.04.18
<Codesignal> Enclose In Brackets  (0) 2020.04.18
<Codesignal> Rectangle Rotation  (1) 2020.04.18

+ Recent posts