SCAU:18067 字符统计

18067 字符统计

时间限制:1000MS  代码长度限制:10KB
提交次数:0 通过次数:0

题型: 填空题   语言: G++;GCC;VC

Description

编写一个函数,统计一个字符串中字母、数字和空格的个数。使用全局变量存放字母和数字个数,函数返回值是空格个数

#include <stdio.h>
#include <string.h>
#include <math.h>

int nL=0, nN=0;

int statistics(char *s)
{
    _______________________
}

int main()
{
    char s[81];
    int nS;
    gets(s);
    nS = statistics(s);

    printf("%d %d %d\n", nL, nN, nS);
    return 0;
}

 

输入格式

输入一行字符,以'\n'符结束

输出格式

统计结果

输入样例

Ab 45

输出样例

2 2 1
#include <stdio.h>
#include <string.h>
#include <math.h>

int nL=0, nN=0;

int statistics(char *s)
{
    int n=0;
    while(*s!='\0')
    {

        if(*s>='a'&&*s<='z'||*s>='A'&&*s<='Z')
        nL++;
        if(*s>='0'&&*s<='9')
        nN++;
        if(*s==' ')
        n++;
        s++;
    }
    return n;
}

int main()
{
    char s[81];
    int nS;
    gets(s);
    nS = statistics(s);

    printf("%d %d %d\n", nL, nN, nS);
    return 0;
}

 

相关推荐

  1. SCAU:18067 字符统计

    2023-12-16 21:42:03       36 阅读
  2. SCAU18063 圈中的游戏

    2023-12-16 21:42:03       44 阅读
  3. 字符个数统计

    2023-12-16 21:42:03       37 阅读
  4. KY127 统计字符

    2023-12-16 21:42:03       23 阅读
  5. 1042 字符统计

    2023-12-16 21:42:03       20 阅读
  6. 统计字符次数

    2023-12-16 21:42:03       14 阅读
  7. c++统计字符出现次数

    2023-12-16 21:42:03       20 阅读

最近更新

  1. gradle安卓开发软件简介

    2023-12-16 21:42:03       0 阅读
  2. UE5.2 AI实时抠像(无需绿幕) + OBS推流直播 全流程

    2023-12-16 21:42:03       0 阅读
  3. 微软Edge浏览器全解析

    2023-12-16 21:42:03       0 阅读
  4. toString方法介绍

    2023-12-16 21:42:03       0 阅读
  5. LLM大语言模型知识点整理

    2023-12-16 21:42:03       0 阅读
  6. 使用Boost.Asio编写TCP通信程序框架(一)

    2023-12-16 21:42:03       0 阅读
  7. 导师好奇我为什么开发后端模版只花了一小时!

    2023-12-16 21:42:03       1 阅读
  8. android 7.0 tts文字转语音

    2023-12-16 21:42:03       1 阅读

热门阅读

  1. 力扣94. 二叉树的中序遍历

    2023-12-16 21:42:03       33 阅读
  2. LeetCode215. Kth Largest Element in an Array

    2023-12-16 21:42:03       35 阅读
  3. C语言—每日选择题—Day49

    2023-12-16 21:42:03       34 阅读
  4. Android audio设置投屏和喇叭双输出

    2023-12-16 21:42:03       57 阅读
  5. 2276. 统计区间中的整数数目

    2023-12-16 21:42:03       39 阅读
  6. C++改写为C

    2023-12-16 21:42:03       41 阅读
  7. JVM源码剖析之信号处理机制

    2023-12-16 21:42:03       27 阅读
  8. Ubuntu 命令行安装 Clang 16或者Clang 17的过程

    2023-12-16 21:42:03       39 阅读