Codesignal

<Codesignal> Is Case-Insensitive Palindrome?

우현짱짱 2020. 4. 19. 15:56

Easy

Given a string, check if it can become a palindrome through a case change of some (possibly, none) letters.

Example

  • For inputString = "AaBaa", the output should be
    isCaseInsensitivePalindrome(inputString) = true.

    "aabaa" is a palindrome as well as "AABAA", "aaBaa", etc.

  • For inputString = "abac", the output should be
    isCaseInsensitivePalindrome(inputString) = false.

    All the strings which can be obtained via changing case of some group of letters, i.e. "abac", "Abac", "aBAc" and 13 more, are not palindromes.

Input/Output

  • [execution time limit] 0.5 seconds (c)

  • [input] string inputString

    Non-empty string consisting of English letters.

    Guaranteed constraints:
    4 ≤ inputString.length ≤ 10.

  • [output] boolean

[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 isCaseInsensitivePalindrome(char *inputString)
{
	for(int i=0;i<strlen(inputString)/2;i++)
		if(tolower(inputString[i])!=tolower(inputString[strlen(inputString)-i-1]))
			return false;

	return true;
}
728x90