当前位置:网站首页>Exercise 6-1 classify and count the number of characters
Exercise 6-1 classify and count the number of characters
2022-07-03 14:09:00 【ᯤ⁹ᴳ⁺ ·】
exercises 6-1 Classify and count the number of characters (15 branch )
This question requests to realize a function , Statistics of Chinese and English letters in a given string 、 Space or enter 、 The number of numeric characters and other characters .
Function interface definition :
void StringCount( char s[] );
among char s[]
Is the string passed in by the user . function StringCount
Must be in one line according to
letter = The number of English letters , blank = The number of spaces or carriage returns , digit = Number of characters , other = The number of other characters
Format output .
Sample referee test procedure :
#include <stdio.h>
#define MAXS 15
void StringCount( char s[] );
void ReadString( char s[] ); /* By the referee , Omit no watch */
int main()
{
char s[MAXS];
ReadString(s);
StringCount(s);
return 0;
}
/* Your function will be put here */
sample input :
aZ &
09 Az
sample output :
letter = 4, blank = 3, digit = 2, other = 1
void StringCount(char s[]){
int letter=0,blank=0,digit=0,other=0,i=0;
do{
if(s[i]>='a'&&s[i]<='z'||s[i]>='A'&&s[i]<='Z'){
letter++;
}else if(s[i]==' '||s[i]=='\n'){
blank++;
}else if (s[i] >= '0' && s[i] <= '9'){
digit++;
}else{
other++;
}
i++;
}while(s[i]!='\0');
printf("letter = %d, blank = %d, digit = %d, other = %d", letter, blank, digit, other);
}
边栏推荐
- Generate directories from web content
- MySQL data processing value addition, deletion and modification
- Metal organic framework MOFs loaded with non steroidal anti-inflammatory drugs | zif-8 wrapped Prussian blue loaded quercetin (preparation method)
- Qt学习19 Qt 中的标准对话框(上)
- Current situation, analysis and prediction of information and innovation industry
- 消息订阅与发布
- Qt学习17 对话框及其类型
- Qt学习22 布局管理器(一)
- js . Find the first palindrome string in the array
- jvm-类加载
猜你喜欢
信创产业现状、分析与预测
Using registered classes to realize specific type matching function template
Solve MySQL 1045 access denied for user 'root' @ 'localhost' (using password: yes)
Message subscription and publishing
Qt学习25 布局管理器(四)
“又土又穷”的草根高校,凭什么被称为“东北小清华”?
jvm-类加载
jvm-运行时数据区
JVM runtime data area
Redis: redis data structure and key operation commands
随机推荐
Analysis of the characteristics of page owner
JS continues to explore...
28:第三章:开发通行证服务:11:在配置文件中定义属性,然后在代码中去获取;
Cross linked cyclodextrin metal organic framework loaded methotrexate slow-release particles | metal organic porous material uio-66 loaded with flavonoid glycosides | Qiyue
Qt学习23 布局管理器(二)
Simulated access
Go 1.16.4: purpose of go mod tidy
金属有机骨架材料ZIF-8包载姜黄素([email protected]纳米颗粒)|纳米金属有机框架搭载雷帕霉素|科研试剂
Go language web development series 29: Gin framework uses gin contrib / sessions library to manage sessions (based on cookies)
Doxorubicin loaded on metal organic framework MIL-88 DOX | folic acid modified uio-66-nh2 doxorubicin loaded [email
Metal organic framework MOFs loaded with non steroidal anti-inflammatory drugs | zif-8 wrapped Prussian blue loaded quercetin (preparation method)
Selenium browser (1)
Summary of common error reporting problems and positioning methods of thrift
如何使用lxml判断网站公告是否更新
Solution to failure or slow downloading of electron when electron uses electron builder to package
Solve the problem of dormitory router campus network sharing login
JVM系列——概述,程序计数器day1-1
Collection of mobile adaptation related articles
Use and design of Muduo buffer class
Go language web development series 30: gin: grouping by version for routing