Easy
Given a string, your task is to replace each of its characters by the next one in the English alphabet; i.e. replace a with b, replace b with c, etc (z would be replaced by a).
Example
For inputString = "crazy", the output should be alphabeticShift(inputString) = "dsbaz".
Input/Output
-
[execution time limit] 0.5 seconds (c)
-
[input] string inputString
A non-empty string consisting of lowercase English characters.
Guaranteed constraints:
1 ≤ inputString.length ≤ 1000. -
[output] string
- The resulting string after replacing each of its characters.
[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 *alphabeticShift(char *inputString)
{
for(int i=0;i<strlen(inputString);i++)
{
inputString[i]++;
if(!isalpha(inputString[i]))
inputString[i]-=26;
}
return inputString;
}
728x90
'Codesignal' 카테고리의 다른 글
<Codesignal> Circle of Numbers (0) | 2020.04.05 |
---|---|
<Codesignal> chessBoardCellColor (0) | 2020.04.05 |
<Codesignal> variableName (0) | 2020.04.05 |
<Codesignal> evenDigitsOnly (0) | 2020.04.05 |
<Codesignal> Array Replace (0) | 2020.04.05 |