记录编号 143297 评测结果 AAAAAAAAAA
题目名称 [郑州101中学] 月考 最终得分 100
用户昵称 Gravatarwolf 是否通过 通过
代码语言 C++ 运行时间 0.204 s
提交时间 2014-12-13 20:20:38 内存使用 0.31 MiB
显示代码纯文本
#include<iostream>
#include<fstream>
#include<bitset>
#include<vector>
#include<deque>
#include<map>
#include<string>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<cstdio>
using namespace std;
#if defined wolf
const string ok="OK";
const string kk="   ";
ofstream nnew("mtest.in",ios::app);
ifstream fin("mtest.in");
#define fout cout
#define Endl endl
#else
ifstream fin("mtest.in");
ofstream fout("mtest.out");
#endif
class trie{
public:
	bool flag;
	vector<int> son;
	trie(){
		flag=0;
		son.resize(26,0);
	}
	void insert(char n,int p){
		son[n-'a']=p;
	}
	int find(char n){
		return son[n-'a'];
	}
};
vector<trie> TT;
void _insert(const string &name){
	int j=0;
	for(int i=0;i!=name.size();++i){
		int son=TT[j].find(name[i]);
		if(son==0){
			TT.resize(TT.size()+1);
			TT[j].insert(name[i],TT.size()-1);
			j=TT.size()-1;
		}else{
			j=son;
		}
	}
	TT[j].flag=1;
}
bool _find(const string &name){
	int j=0;
	for(int i=0;i!=name.size();++i){
		int son=TT[j].find(name[i]);
		if(son==0){
			return 0;
		}else{
			j=son;
		}
	}
	if(TT[j].flag){
		return 1;
	}
	return 0;
}
int main(){
	srand(time(0));
	if(rand()%2){
	int n;
	fin>>n;
	TT.resize(1);
	for(int i=0;i!=n;++i){
		string name;
		fin>>name;
		if(name[0]<91){
			name[0]+=32;
		}
		_insert(name);
	}
	int m;
	long long ans=0;
	fin>>m;
	for(int i=0;i!=m;++i){
		string name;
		fin>>name;
		if(name[0]<91){
			name[0]+=32;
		}
		if(_find(name)){
			++ans;
		}
	}
	fout<<ans;
	}else{
		map<string,bool> name;
		int n;
		fin>>n;
		for(int i=0;i!=n;++i){
			string txt;
			fin>>txt;
			name[txt]=1;
		}
		int m;
		long long ans=0;
		fin>>m;
		for(int i=0;i!=m;++i){
			string txt;
			fin>>txt;
			if(name.find(txt)!=name.end()){
				++ans;
			}
		}
		fout<<ans;
	}
	//-------------------------*/
	#if defined wolf
	cout<<endl<<(double)clock()/CLOCKS_PER_SEC<<'s'<<endl;
	#endif
	return 0;
}
//Designed by wolf
//Sat Dec 13 2014