All submissions

Check if the String Numeric or Alphabetic

Code

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

bool is_num(char s){
    return (s>='0' && s<='9');
}
bool is_alpha(char s){
    return (s>='a' && s<='z') || (s>='A' && s<='Z');
}
void classify_string(const char *str) {
    // Your logic here
    int len = strlen(str);
    int cnt_num = 0, cnt_alpha = 0;
    for(int i=0;i<len;i++){
        if(is_alpha(str[i])) cnt_alpha++;
        if(is_num(str[i])) cnt_num++;
    }
    if(cnt_alpha == len) printf("ALPHABETIC");
    else if(cnt_num == len) printf("NUMERIC");
    else printf("MIXED");
}

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