All submissions

Check if the String Numeric or Alphabetic

 

#include <stdio.h>
#include <stdint.h>

void classify_string(const char *str) {
    // Your logic here
    // Check if string is empty
    if (str[0] == '\0') 
    {
        printf("MIXED");
        return;
    }
    
    int has_digit = 0;
    int has_alpha = 0;
    int has_other = 0;
    
    int i = 0;
    while (str[i] != '\0') 
    {
        char c = str[i];
        
        // Check if digit (ASCII 48-57 for '0'-'9')
        if (c >= '0' && c <= '9') 
        {
            has_digit = 1;
        }
        // Check if alphabetic (ASCII 65-90 for 'A'-'Z', 97-122 for 'a'-'z')
        else if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')) 
        {
            has_alpha = 1;
        }
        // Anything else (symbols, spaces, etc.)
        else 
        {
            has_other = 1;
        }
        
        i++;
    }
    
    // Determine classification
    if (has_other || (has_digit && has_alpha)) 
    {
        printf("MIXED");
    }
    else if (has_digit) 
    {
        printf("NUMERIC");
    }
    else if (has_alpha) 
    {
        printf("ALPHABETIC");
    }

}

int main() {
    char str[101];
    fgets(str, sizeof(str), stdin);

    // Remove newline
    uint8_t i = 0;
    while (str[i]) {
        if (str[i] == '\n') {
            str[i] = '\0';
            break;
        }
        i++;
    }

    classify_string(str);
    return 0;
}

 

 

 

 

Loading...

Input

123456

Expected Output

NUMERIC