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

OLE到跪了!!!!求解释。

Posted by liuweibiao at 2012-07-21 11:07:49 on Problem 1035
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int n,m,t;
string str;
struct node
{
	string s;
	int pos;
}a[11000],p[11000];
int cmp(const node &t1,const node &t2)
{
	if(t1.s.length ()==t2.s.length ())
		return t1.s<t2.s;
	return t1.s.length ()<t2.s.length ();
}
int cmp1(const node &t1,const node &t2)
{
	return t1.pos<t2.pos;
}

int main()
{
	n=0;
	int i,j,k;
	//freopen("f:\\testin.txt","r",stdin);
	while(cin>>str)
	{
		if(str=="#")
			break;
		a[n].pos=n;
		a[n++].s=str;
	}
	sort(a,a+n,cmp);
	while(cin>>str)
	{
		if(str=="#")
			break;
		i=0;
		j=n;
		if(a[0].s==str)
		{
			cout<<str<<" is correct"<<endl;
			continue;
		}
		m=0;
		while(i<=j)
		{
			k=i+j>>1;
			if(a[n-1].s==str||a[k].s==str)
			{
				cout<<str<<" is correct"<<endl;
				m=1;
				break;
			}
			else if(a[k].s.length ()<str.length ()||a[k].s.length ()==str.length ()&&a[k].s<str)
				i=k+1;
			else j=k-1;
		}
		if(m)
			continue;
		i=0;
		j=n;
		cout<<str<<":";
		int beg=0;
		while(i<=j)
		{
			if(str.length ()+1<=a[0].s.length ())
				break;
			k=i+j>>1;
			if(a[k].s.length ()>=str.length ()-1&&a[k-1].s.length ()<str.length ()-1)
			{
				beg=k;
				break;
			}
			else if(a[k].s.length ()<str.length ()-1)
				i=k+1;
			else j=k-1;
		}
		t=0;
		for(i=beg;a[i].s.length ()<str.length ()+2;i++)
		{
			m=0;
			k=0;
			for(j=0;j<str.length ()&&k<a[i].s.length ();j++,k++)
			{
				if(a[i].s[k]==str[j])
				{
					m++;
				}
				else if(a[i].s.length ()<str.length ())
					k--;
				else if(a[i].s.length ()>str.length ())
					j--;
			}
			if(str.length ()>=a[i].s.length ()&&m==str.length ()-1||m==str.length ())
				p[t++]=a[i];
		}
		sort(p,p+t,cmp1);
		for(i=0;i<t;i++)
			cout<<' '<<p[i].s;
		cout<<endl;
	}
}

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