Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

不用所谓搜索方法,从头到尾搜索,ac了

Posted by jencol at 2008-12-06 09:20:44 on Problem 3193
#include<iostream>
#include<set>
#include<string>
using namespace std;

int Mystrcmp(char* str,char* book)
{
	char cc[61];
	int sl=strlen(str);
	int bl=strlen(book);
	if(sl<bl)
	{
		memcpy(cc,book,sl);
		return strcmp(str,cc);
	}
	else if(sl>bl)
	{
		memcpy(cc,str,bl);
		return strcmp(cc,book);
	}
	else
		return strcmp(str,book);
}


int main()
{
	int m,n;
	set<string> s;
	set<string>::iterator it;
	char book[1000][61];
	memset(book,0,sizeof(book));
	char str[100];
	cin>>m>>n;
	getchar();
	for(int i=0;i<m;i++){gets(str);s.insert(str);}

	int k=0;
	for(it=s.begin();it!=s.end();it++)
	{
		strcpy(book[k],(*it).c_str());
		book[k][strlen(book[k])]='\0';
		k++;
	}

	int sum=0;
	while(n--)
	{
		gets(str);

		int j;int len;
		int slen=strlen(str);
		int i=0;
		while(i<m && book[i++][0]<str[0]);
		if(book[--i][0]>str[0]) continue;
		for(;i<m;i++)
		{
			int ll=strlen(book[i]);
			len=ll>slen?slen:ll;
			for(j=0;j<len;j++)
			{
				if(book[i][j]!=str[j])	break;
			}
			if(j==len) {sum++;break;}
		}
	}
	cout<<sum<<endl;
	return 0;
}


 


Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator