C + + brush question--1910: character statistics

Source: Internet
Author: User

Description

Give a string of characters, asking for the number of letters, numbers, spaces, and other characters to be counted. Letters: A, B, ..., z, A, b, ..., z compose numbers: 0, 1, ..., 9 spaces: "" (not including quotation marks) the remainder of the printable word embox to other characters.

Input

There are several sets of test data. Each group of data is one line (not more than 100000). Data to end of file (EOF).

Output

Each set of inputs corresponds to a row of output. Includes four integers a B c D, representing the number of letters, numbers, spaces, and other characters, respectively.

#include <iostream> #include <cstdio>using namespace Std;int main () {    char a[81];    int n,b,c,d;    while (gets (a))    {        n=b=c=d=0;        for (int i=0;a[i]!= ' n '; i++)        {            if (a[i]>= ' 0 ' &&a[i]<= ' 9 ')                n++;            else if ((a[i]>= ' a ' &&a[i]<= ' z ') | | (a[i]>= ' A ' &&a[i]<= ' Z '))                b++;            else if (a[i]== ')                C + +;            else                d++;        }        cout<<b<< ' <<n<< ' <<c<< ' <<d<<endl;    }    return 0;}

Learn to Harvest: the input string can be a,cin>>a with string, write the top file # include <string> can, or use char a[81],gets (a), write the top file # include < Cstdio> can do it. Experience: The more write more self-confidence, continue to refuel it, first solve small problems, lay a good foundation!

C + + brush question--1910: character statistics

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.