|
发表于 2021-10-21 20:15:26
|
显示全部楼层
- #include <stdio.h>
- int main(void)
- {
- int a , b , d , o , s ;
- char c ;
- for(a = b = d = o = s = 0 ; (c = getchar())!= '\n' ;) {
- if(c >= ' ' && c <= '~') {
- if((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')) a ++ ;
- else if(c == ' ') b ++ ;
- else if(c >= '0' && c <= '9') d ++ ;
- else s ++ ;
- } else {
- o ++ ;
- }
- }
- printf("alphabet : %d\n" , a) ;
- printf(" blank : %d\n" , b) ;
- printf(" digit : %d\n" , d) ;
- printf(" symbol : %d\n" , s) ;
- printf(" other : %d\n" , o) ;
- }
复制代码
编译、运行实况:
- D:\00.Excise\C>cl x.c
- 用于 x86 的 Microsoft (R) C/C++ 优化编译器 19.28.29334 版
- 版权所有(C) Microsoft Corporation。保留所有权利。
- x.c
- Microsoft (R) Incremental Linker Version 14.28.29334.0
- Copyright (C) Microsoft Corporation. All rights reserved.
- /out:x.exe
- x.obj
- D:\00.Excise\C>x
- SFEWW@#^*)ytjykil{};".<Mn~!@#RT&*&9054
- alphabet : 16
- blank : 0
- digit : 4
- symbol : 18
- other : 0
- D:\00.Excise\C>
复制代码 |
|