HDU 2017 string Statistics (Java)

Source: Internet
Author: User

Problem:

The main subject is the processing of string input:

String A=cin.next ();

Char [] S=a.tochararray ();


String statisticsTime limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 51624 Accepted Submission (s): 28327


Problem description for a given string, statistics the number of occurrences of a numeric character.
Input data has multiple lines, the first line is an integer n, indicating the number of test instances, followed by n rows, each containing a string consisting of letters and numbers.
Output for each test instance, outputs the number of values in the string, with each output occupying one row.
Sample Input
2asdfasdf123123asdfasdfasdf111111111asdfasdfasdf

Sample Output
69


Code:

Import java.util.*;p ublic class main{public static void Main (String args[]) {Scanner cin=new Scanner (system.in); while ( Cin.hasnext ()) {int n=cin.nextint (); for (int i=0;i<n;i++) {String a=cin.next (); Char [] s=a.tochararray (); int sum=0; for (int j=0;j<s.length;j++) {if (s[j]>= ' 0 ' &&s[j]<= ' 9 ') sum+=1;} SYSTEM.OUT.PRINTLN (sum);}}}


HDU 2017 string Statistics (Java)

Related Article

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.