Medium
A media access control address (MAC address) is a unique identifier assigned to network interfaces for communications on the physical network segment.
The standard (IEEE 802) format for printing MAC-48 addresses in human-friendly form is six groups of two hexadecimal digits (0 to 9 or A to F), separated by hyphens (e.g. 01-23-45-67-89-AB).
Your task is to check by given string inputString whether it corresponds to MAC-48 address or not.
Example
- For inputString = "00-1B-63-84-45-E6", the output should be
isMAC48Address(inputString) = true; - For inputString = "Z1-1B-63-84-45-E6", the output should be
isMAC48Address(inputString) = false; - For inputString = "not a MAC-48 address", the output should be
isMAC48Address(inputString) = false.
Input/Output
-
[execution time limit] 0.5 seconds (c)
-
[input] string inputString
Guaranteed constraints:
15 ≤ inputString.length ≤ 20. -
[output] boolean
- true if inputString corresponds to MAC-48 address naming rules, 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 isMAC48Address(char *inputString)
{
if(strlen(inputString)!=17)
return false;
for(int i=0;i<strlen(inputString);i++)
if(!(i%3==2?inputString[i]=='-':isdigit(inputString[i])||'A'<=inputString[i]&&'F'>=inputString[i]))
return false;
return true;
}
728x90
'Codesignal' 카테고리의 다른 글
<Codesignal> lineEncoding (0) | 2020.04.06 |
---|---|
<Codesignal> isDigit (0) | 2020.04.06 |
<Codesignal> Elections Winners (0) | 2020.04.06 |
<Codesignal> buildPalindrome (0) | 2020.04.05 |
<Codesignal> isBeautifulString (0) | 2020.04.05 |