首页 > 其他分享 >数组~Count digits from a text stream

数组~Count digits from a text stream

时间:2022-11-07 21:35:28浏览次数:42  
标签:Count digits EOF stream int text other

题目描述

Count digits, white spaces(‘ ’,’\n’ ,’\t’) and other characters from a text stream ending with EOF.

输入

A text stream ending with EOF

输出

Print the numbers of digits, white spaces and other characters in three lines.

样例输入

This is a test.
It has 2 lines and 9 spaces.

样例输出

digit=2
white space=11
other=32

#include<stdio.h>
int main(){
    char n;
    //int digit[1000]={0};
    int whitespece=0;
    int other=0;
    int digits=0;
    while((n=getchar())!=EOF){
        if(n==' ' || n=='\t' || n=='\n')
            whitespece++;
        else if(n>='0' && n<='9')
            digits++;
        else
            other++;
    }
    printf("digit=%d\nwhite space=%d\nother=%d\n",digits,whitespece,other);
    return 0;
}

 

标签:Count,digits,EOF,stream,int,text,other
From: https://www.cnblogs.com/luoxiaoluo/p/16867537.html

相关文章

  • Service Account
    在kubernetes中,有两种类型的账号,用户账号和服务账号;用户账号被用户所使用,服务账号被机器所使用;用户账号能够被管理员用作管理集群,或被开发人员用来在集群中部署应用;服......
  • Streamlit 简介
    Streamlit是第一个专门针对机器学习和数据科学团队的应用开发框架,它是开发自定义机器学习工具的最快的方法,你可以认为它的目标是取代Flask在机器学习项目中的地位,可以帮助......
  • SqlServer 使用 count功能查询数量
     1、返回的是一个object类型,也就是说是所有数据类型的基类,可根据select所得的第一列的数据类型转换为对应的数据类型intcount=(int)cmd.ExecuteScalar();2、当sel......
  • CentOS Stream 安装 Nacos
    版本LinuxCentOSStreamrelease8Nacos2.0.3MySQL8.0.29Step1:下载并解压unzipnacos-server-$version.zip#或者tar-zxvfnacos-server-$ve......
  • VMware 16 安装 CentOS Stream
    环境版本Windows10VMwareWorkstation16ProCentOS8-stream下载CentOS8stream安装包点击阿里云开源镜像站或网易开源镜像站,选择要下载的版......
  • 006 Rust 异步编程,Stream 介绍
    Stream介绍​​Stream​​​和​​Future​​​类似,但是​​Future​​​对应的是一个​​item​​​的状态的变化,而​​Stream​​​则是类似于​​iterator​​​,在结束......
  • java--Stream流基础
    Stream流操作方法执行完此方法之后,Stream流依然可以继续执行其他操作Stream流的思想 Stream流的三类方法  获取Stream流    好比创建一条流水线,并把数据放......
  • 【模板】popcount
    postedon2022-02-0418:11:33|under模板|sourceintpopcount(intx){#defineBIT2(n)n,n+1,n+1,n+2#defineBIT4(n)BIT2(n),BIT2(n+1),BIT2(n+1),BIT2......
  • 并发工具之 Semaphore & CountDownLatch
    1.semaphore是什么?Semaphore字面意思是信号量的意思。它的作用是控制访问特定资源的线程数量,底层依赖AQS的状态state,是生产中比较常用的一个工具类。(基于共享模式)//......
  • counting-in-2d
    【模板】二维数点postedon2022-10-2313:50:24|under模板|sourceproblem给定一个二维平面,多次询问$x\in[l_x,r_x],y\in[l_y,r_y]$的点有多少个。solution1(静......