Easy
You are implementing your own HTML editor. To make it more comfortable for developers you would like to add an auto-completion feature to it.
Given the starting HTML tag, find the appropriate end tag which your editor should propose.
Example
- For startTag = "<button type='button' disabled>", the output should be
htmlEndTagByStartTag(startTag) = "</button>"; - For startTag = "<i>", the output should be
htmlEndTagByStartTag(startTag) = "</i>".
Input/Output
-
[execution time limit] 0.5 seconds (c)
-
[input] string startTag
Guaranteed constraints:
3 ≤ startTag.length ≤ 75. -
[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 *htmlEndTagByStartTag(char *startTag)
{
char *str=(char *)calloc(100,sizeof(char));
str[0]='<';
str[1]='/';
for(int i=1;!isspace(startTag[i]) && startTag[i]!='>';i++)
str[i+1]=startTag[i];
str[strlen(str)]='>';
return str;
}
728x90
'Codesignal' 카테고리의 다른 글
<Codesignal> Is Substitution Cipher? (0) | 2020.04.19 |
---|---|
<Codesignal> Strings Construction (0) | 2020.04.19 |
<Codesignal> Find Email Domain (0) | 2020.04.19 |
<Codesignal> Is Case-Insensitive Palindrome? (0) | 2020.04.19 |
<Codesignal> Is Tandem Repeat? (0) | 2020.04.19 |