Codesignal
<Codesignal> Reflect String
우현짱짱
2020. 5. 24. 11:12
Easy
Define an alphabet reflection as follows: a turns into z, b turns into y, c turns into x, ..., n turns into m, m turns into n, ..., z turns into a.
Define a string reflection as the result of applying the alphabet reflection to each of its characters.
Reflect the given string.
Example
For inputString = "name", the output should be
reflectString(inputString) = "mznv".
Input/Output
-
[execution time limit] 0.5 seconds (c)
-
[input] string inputString
A string of lowercase characters.
Guaranteed constraints:
3 ≤ inputString.length ≤ 1000. -
[output] string
[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
char *reflectString(char *inputString)
{
for(int i=0;i<strlen(inputString);i++)
inputString[i]='a'+'z'-inputString[i];
return inputString;
}
728x90