All pastes #165870 Raw Edit

Rave Hanker

public cpp v1 · immutable
·published 2006-09-10 08:22 UTC
rendered paste body
#include <iostream>#include <vector>#include <string>#include <cctype>using namespace std;#define RDBGbool matchStr (string pat, string inp){	int i, j;	for (i=j=0; inp[i] && pat[j]; ) {		if (tolower(inp[i]) == tolower(pat[j]))  {			while (inp[i] && pat[j] && tolower(inp[i]) == tolower(pat[j])) {				i++, j++;			}			j--;			while (inp[i] && pat[j] && tolower(inp[i]) == tolower(pat[j])) {				i++;			}			j++;		}		else {			return false;		}	}	if (!inp[i] && !pat[j]) 		return true;	return false;}int countKeywords(string subjectLine, vector <string> keywords){	string inp;	int ans;	ans = 0;	for (int i=0; subjectLine[i]; i++) {		inp="";		for ( ;subjectLine[i] && subjectLine[i] !=' '; i++) {			inp += subjectLine[i];		}		for (vector<string>::iterator it = keywords.begin(); it!=keywords.end(); it++) {			if (matchStr(*it, inp)) {#ifdef RDBG				cout<<inp<<" "<<*it<<endl;#endif				ans++;				break;			}		}	}	return ans;}int main(){	string subjectLine, tmp;	char arr[100];	vector<string> keywords;	cin.getline(arr, 99);	subjectLine = arr;	while (cin>>tmp) {		if (tmp=="0")			break;		if (find (keywords.begin(), keywords.end(), tmp) == keywords.end())			keywords.push_back(tmp);	}	cout<<countKeywords(subjectLine, keywords)<<endl;	return 0;}