Easy
Correct variable names consist only of English letters, digits and underscores and they can't start with a digit.
Check if the given string is a correct variable name.
Example
- For name = "var_1__Int", the output should be
variableName(name) = true; - For name = "qq-q", the output should be
variableName(name) = false; - For name = "2w2", the output should be
variableName(name) = false.
Input/Output
-
[execution time limit] 0.5 seconds (c)
-
[input] string name
Guaranteed constraints:
1 ≤ name.length ≤ 10. -
[output] boolean
- true if name is a correct variable name, false otherwise.
[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 variableName(char *name)
{
if(isdigit(name[0]))
return false;
for(int i=0;i<strlen(name);i++)
if(!(isalnum(name[i]) || name[i]=='_'))
return false;
return true;
}
728x90
'Codesignal' 카테고리의 다른 글
<Codesignal> chessBoardCellColor (0) | 2020.04.05 |
---|---|
<Codesignal> alphabeticShift (0) | 2020.04.05 |
<Codesignal> evenDigitsOnly (0) | 2020.04.05 |
<Codesignal> Array Replace (0) | 2020.04.05 |
<Codesignal> Minesweeper (0) | 2020.04.05 |