HDU 1860 statistical characters

Source: Internet
Author: User

 

Problem description: count the number of times a specified character appears in a given string. Input a number of test cases. Each test case contains 2 rows. 1st actions: a string of no more than 5 characters, 2nd act as a string of no more than 80 characters. Note that the string contains spaces, which may also be one of the characters to be counted. When '#' is read, the input ends, and the corresponding results are not output. For each test case, the output counts the number of times each character of the string in the second line appears in the string in the second line. The output is in the following format: C0 N0 C1 N1 C2 N2... among them, CI is the I character in line 1st, and Ni is the number of times that CI appears. Sample Input
 
Ithis Is A testi ngthis is a long test string #
Sample output
 
I 2I 3 5N 2G 2 Note: In 2nd test cases, spaces are also one of the statistical characters.


# Include <stdio. h>

# Include <string. h>

Int main ()

{

Int I, j, M [101] = {0}, L, K;

Char C [6], n [81];

While (gets (c) & C [0]! = '#')

{

Gets (N );

L = strlen (C );

K = strlen (N );

For (I = 0; I <101; I ++)

{

M [I] = 0;

}

For (I = 0; I <L; I ++)

For (j = 0; j <K; j ++)

If (N [J] = C [I])

{

M [I] ++;

}

For (I = 0; I <L; I ++)

Printf ("% C % d \ n", C [I], M [I]);

}

}

 

 


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.