Statistic character Time limit:1000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 11683 accepted Submission (s): 7298
Problem Description counts the number of occurrences of a specified character in a given string
Input test entry contains several test cases, each containing 2 lines, the 1th behavior a string of not more than 5 in length, and the 2nd behavior a string that is no longer than 80. Note that the string here contains spaces, or spaces, which may be one of the characters that are required to be counted. When you read ' # ' The input ends and the corresponding result is not output.
Output for each test case, the number of occurrences of each character of the string in line 1th in the 2nd line string, as shown in the following format:
C0 N0
C1 N1
C2 N2
...
Where CI is the first character in line 1th, NI is the number of CI occurrences.
Sample Input
I am a test I ng this is a long test string #
Sample Output
I 2 I 3 5 N 2 G 2 Note: In the 2nd Test case, a space is also one of the characters being counted. The stroke, the stroke, the recent state of mind a little explode ...
#include <iostream>
#include <cstring>
using namespace std;
int main ()
{
string a,b;
while (Getline (cin,a) &&a[0]!= ' # ') {
getline (cin,b);
for (int i=0;a[i];i++) {
int ans=0;
for (int j=0;b[j];j++)
if (A[i]==b[j])
ans++;
cout<<a[i]<< ' <<ans<<endl;
}
}
return 0;
}