hdu-1860--statistic characters

Source: Internet
Author: User
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;
}


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.