"Huawei OJ platform Exercises" statistics a string containing the number of spaces, English, numbers

Source: Internet
Author: User

Statistics A string contains the number of spaces, English, and numbers # include <iostream>using namespace Std;void processstring (char* s) {int n = strlen (s); int Kg=0;int shuzi=0;int yingwen=0;if (n>0) {for (int a=0;a<n;a++) {if (s[a]== ') kg++;if (s[a]<= ' 9 ' &&s[a] >= ' 0 ') shuzi++;if (s[a]<= ' z ' &&s[a]>= ' a ') yingwen++;if (s[a]<= ' z ' &&s[a]>= ' a ') Yingwen ++;} cout<<s<< "contains the number of spaces:" <<kg<<endl;cout<<s<< "contains numbers:" <<shuzi<<endl ;cout<<s<< "contains the number of English:" <<yingwen<<endl;}} int main () {char s[100];cout<< "Please enter a string:"; Cin.getline (s,100);p rocessstring (s); return 0;}

The space at the end of the string can also be recognized by the effect.

Note: The input string cannot be used Cin>>, because it is automatically intercepted when a space is encountered.

To use CIN. The Getline () function reads the entire row.



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

"Huawei OJ platform Exercises" statistics a string containing the number of spaces, English, numbers

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.