Count multi-line characters

Count multi-line characters

Given an article, there are 3 lines of text, and each line has a maximum of 80 characters. It is required to separately count the number of English uppercase letters, lowercase letters, numbers, spaces and other characters.

Enter a total of 3 lines, indicating the input article.

Output the number of English uppercase letters, lowercase letters, numbers, spaces, and other characters in the article on one line, separated by spaces.
Please pay attention to the line ending output.
enter

I am a program.
This is the second line!
And this is the last line........

Output

3 47 0 12 10
//统计多行字符
#include<iostream>
#include<string>
#define N 80		//单行字符上限
using namespace std;
int main(void)
{
    
    
    char a[3][N];		//三行
    int i,j, up=0, low=0, num=0, sp=0, other=0;
    for (i=0;i<3; i++)
        gets(a[i]);
    for (i=0;i<3;i++)
    {
    
    
        for (j=0;a[i][j]!='\0';j++)
        {
    
    
            if (a[i][j]>='A'&&a[i][j]<='Z')
                up++;
            else if (a[i][j]>='a'&&a[i][j]<='z')
                low++;
            else if (a[i][j]>='0'&&a[i][j]<='9')
                num++;
            else if (a[i][j]==' ')
                sp++;
            else other++;
        }
         
    }
    cout<<up<<" "<<low<<" "<<num<<" "<<sp<<" "<<other<<" "<<endl;
      
    return 0;
}

Guess you like

Origin blog.csdn.net/qq_45830912/article/details/114102881