判断字符串类型

1199 判断字符串类型

题目描述

输入一个字符串,其中只能包括数字或字母。对应输入的字符串,输出它的类型。如果是仅由数字构成的那么输出digit,如果是仅由字母构成的那么输出character,如果是由数字和字母一起构成的输出mixed。

输入描述

/*
输入一个字符串,长度不超过1000,且字符串中只包括数字或大、小写字母。
*/
Sun2009

输出描述

/*
输出对应的类型。
*/
mixed
#include<stdio.h>
#include<string.h>

void judgetype(char s[]){
    int i=0;
    int numflag = 0;
    int charflag = 0;
    int len = strlen(s);
    for(i=0;i<len;i++){
        if(s[i]>='0' && s[i]<= '9')
            numflag = 1;
        else if(s[i]>='A' && s[i]<= 'z')
            charflag = 1;
    }
    if(numflag && charflag)
        printf("mixed
");
    else if(charflag && !numflag)
        printf("character
");
    else if(numflag && !charflag)
        printf("digit
");
}

int main()
{
    char s[1000];
    scanf("%s",s);
    judgetype(s);
    return 0;
}
原文地址:https://www.cnblogs.com/lwp-nicol/p/14285189.html