Easy
Given a string, enclose it in round brackets.
Example
For inputString = "abacaba", the output should be
encloseInBrackets(inputString) = "(abacaba)".
Input/Output
-
[execution time limit] 0.5 seconds (c)
-
[input] string inputString
Guaranteed constraints:
0 ≤ inputString.length ≤ 10. -
[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 *encloseInBrackets(char *inputString)
{
int N=strlen(inputString);
for(int i=N;i>0;i--)
inputString[i]=inputString[i-1];
inputString[0]='(';
inputString[N+1]=')';
inputString[N+2]='\0';
return inputString;
}
728x90
'Codesignal' 카테고리의 다른 글
<Codesignal> Is Tandem Repeat? (0) | 2020.04.19 |
---|---|
<Codesignal> Proper Noun Correction (0) | 2020.04.18 |
<Codesignal> Rectangle Rotation (1) | 2020.04.18 |
<Codesignal> Weak Numbers (0) | 2020.04.18 |
<Codesignal> Comfortable Numbers (0) | 2020.04.17 |