POJ 2973 unordered string matches with wildcard characters

Source: Internet
Author: User

Test instructions

Two unordered strings are matched with wildcard characters.

Analysis:

The character frequency can be directly counted.

Code:

POJ 2973
//sepnine
#include <iostream>
#include <map>
#include <string>
using namespace std;
String dictionary[1024];
int num[32];
int tmp[32];
int main ()
{
	int i,j,n;
	while (Cin>>n&&n) {for
		(i=1;i<=n;++i)
			cin>>dictionary[i];
		string C;
		cin>>c;			
		int cnt=0,ans=0;
		memset (num,0,sizeof (num));
		For (I=0;i<c.length (); ++i)
			if (c[i]== ' _ ')
				++cnt;		
			else
				++num[c[i]-' A '];
		for (i=1;i<=n;++i) {
			memset (tmp,0,sizeof (TMP));
			For (J=0;j<dictionary[i].length (); ++j)
				++tmp[dictionary[i][j]-' A '];
			int sum=0;
			for (j=0;j<= ' Z '-' A '; ++j)
				if (Tmp[j]>num[j])
					sum+=tmp[j]-num[j];
			if (sum<=cnt)
				++ans;
		}
		printf ("%d\n", ans);
	}
	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.