[洛谷P2264]情书
题目大意:给n个单词和一段话,段落中每出现一次指定单词答案加一,但同一句话中同一个单词只算一次,求答案
题解:暴力匹配
C++ Code:
#include<iostream> #include<algorithm> #include<cstdio> #include<bitset> using namespace std; int n,ans; string s[101],p,tmp; bitset<101>used; int main(){ ios::sync_with_stdio(false); cin>>n;getline(cin,s[0]); for (int i=1;i<=n;i++){ getline(cin,s[i]); transform(s[i].begin(),s[i].end(),s[i].begin(),::tolower); } getline(cin,p);transform(p.begin(),p.end(),p.begin(),::tolower); int len=p.length(); for (int i=0;i<len;i++){ if (p[i]>='a'&&p[i]<='z'){ tmp.push_back(p[i]); }else{ for (int j=1;j<=n;j++)if (tmp==s[j]){used.set(j);break;} tmp=""; if (p[i]=='.'){ ans+=used.count(); used.reset(); } } } printf("%d\n",ans); return 0; }