#include <string.h>
#include <ctype.h>
#define MAXTYPE 4
enum { LOW, UP, DIGIT, OTHER }
int count[MAXTYPE]
float percent[MAXTYPE]
int CharTypeCount(char *s)
{
unsigned char *p
int i
int n
memset(count, '\0', sizeof(count))
p = (unsigned char*)s
n = 0
while (*p) {
if (*p>='a' &&*p<= 'z') {
count[LOW]++
}
else if (*p>='A' &&*p<= 'Z') {
count[UP]++
}
else if (*p>='0' &&*p<= '9') {
count[DIGIT]++
}
else {
count[OTHER]++
}
p++
n++
}
for (i=0i<MAXTYPEi++) {
percent[i] = (count[i]*1.0)/n
}
return n
}
int main()
{
char s[1000]
int i
int n
while(gets(s) != NULL) {
n = CharTypeCount(s)
if (n <=0 ) {
printf("please input a string!\n")
continue
}
printf("a-z: %d/%d %.2f%%\n", count[LOW], n, percent[LOW])
printf("A-Z: %d/%d %.2f%%\n", count[UP], n, percent[UP])
printf("0-9: %d/%d %.2f%%\n", count[DIGIT], n, percent[DIGIT])
printf("OTHER: %d/%d %.2f%%\n", count[OTHER], n, percent[OTHER])
}
return 0
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)