Statistical characters (hangdian 1860)

Source: Internet
Author: User

/* Statistical characters
Problem description
Counts the number of times a specified character appears in a given string.

 

Input
The test input contains several test cases. Each test case contains two rows. 1st act as a string of no more than 5 Characters and 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.
 

Output
For each test case, count the number of times each character of the string in the 1st line appears in the string in the 2nd line, and output it 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
I
This is a test
I ng
This is a long test string
#
 

Sample output
I 2
I 3
5
N 2
G 2
Note: Among the 2nd test cases, space is also one of the statistical characters.

*/
# Include <stdio. h>
# Include <string. h>
Int main ()
{
Int len1, len2;
Char A [6], B [81];
Int C [6], I, J;
While (gets (a) & strcmp (,"#")! = 0) // It cannot be written as while (gets ()! = "#"). If the write operation times out.
{
Int C [6] = {0 };
Gets (B); // gets (B) does not require getchar () to absorb carriage returns; otherwise, it is wrong.
Len1 = strlen ();
Len2 = strlen (B );
For (I = 0; I <len1; I ++)
{
For (j = 0; j <len2; j ++)
{
If (A [I] = B [J])
C [I] ++;
}
Printf ("% C % d \ n", a [I], C [I]);
}
}
Return 0;
}

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.