7.11.7 两个版本

7.11.7

include <stdio.h>

int main(void)
{
char ch;
int lc = 0; // 统计小写字母
int uc = 0; // 统计大写字母
int oc = 0; // 统计其他字母

while ((ch = getchar()) != '#')
{
if (( ch >= 'a' ) && ( ch <= 'z'))
lc++;
else if (!(ch < 'A') && !(ch > 'Z'))
uc++;
else
oc++;
}
printf("%d lowercase, %d uppercase, %d other", lc, uc, oc);
return 0;
}

7.11.7 other version

include <stdio.h>

include <ctype.h>

int main(void)
{
char ch;
int lc = 0; // 统计小写字母
int uc = 0; // 统计大写字母
int oc = 0; // 统计其他字母

while ((ch = getchar()) != '#')
{
if (islower(ch))
lc++;
else if (isupper(ch))
uc++;
else
oc++;
}
printf("%d lowercase, %d uppercase, %d other", lc, uc, oc);
return 0;
}

posted on 2019-04-21 20:34  viviLy  阅读(122)  评论(0)    收藏  举报