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]);
}
}