All submissions

Check if the String Numeric or Alphabetic

Code

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

#define isALPHABETIC(x) (x>=65)&&(x<91) || (x>=97)&&(x<123)
#define isNUMERIC(x) (x>=48)&&(x<58)
#define isSymbol(x) (x>=0)&&(x<48) || (x>=58)&&(x<65) || (x>=91)&&(x<97)  

void classify_string(const char *str) {
    // Your logic here
    int a =0 ;
    int b =0 ;
    int c =0 ;
    int d =0 ;

    while(*str)
    {
        a |= isALPHABETIC(*str);
        b |= isNUMERIC(*str);
        c |= isSymbol(*str);

        str++;
    }

    d = c<<2 | b<<1 | a<<0;

    //printf("0x%X",d);
    switch(d)
    {
        case 0 :
            printf("Unknow");
            return ;
        break;
        case 1 : 
            printf("ALPHABETIC");
            return ;
        break;
        case 2 : 
            printf("NUMERIC");
            return ;
        break;
        case 3 : 
            printf("MIXED");
            return ;
        break;
        case 4 : 
            printf("MIXED (empty string is considered mixed)");
            return ;
        break;
        case 5 : 
            printf("MIXED");
            return ;
        break;
        case 6 :
            printf("MIXED");
            return ; 
        break;
        case 7 : 
            printf("MIXED");
            return ;
        break;
    }
    
}

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;
}

Solving Approach

 

 

 

Loading...

Input

123456

Expected Output

NUMERIC