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

求高手指教,给出的测试都过,不超时 就是WA

Posted by troy24 at 2010-08-10 09:48:03 on Problem 1035
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
using namespace std;
vector<string> ss;

int find(vector<string> vv,string cmp)
{
	int n = vv.size();
	for(int i=0;i<n;i++)
	{
		if(vv[i] == cmp)
		{
			return i;
		}
	}
	return 10000001;
}


string cmp(string str,string cmp)
{
	int len1 = str.length();
	int len2 = cmp.length();
	int i;
	int test = len1 - len2;
	if(abs(test) > 1)
		return "%%";
	int cnt;
	if(test == 0)
	{
		cnt =0;
		for(i=0;i<len1;i++)
		{
			if(str[i] != cmp[i])
			{cnt++;}			
		}
		if(cnt == 1)
			return cmp;
	}
	if(test > 0)
	{
		cnt = 0;
		for(i=0;i<len1;i++)
		{
			if(cmp.find(str[i]) < 10000)cnt++;
		}
		if(cnt == len2)
			return cmp;
	}
	if(test < 0)
	{
		cnt = 0;
		for(i=0;i<len1;i++)
		{
			if(cmp.find(str[i]) < 10000)cnt++;
		}
		if(cnt == len1)
			return cmp;
	}
	return "%%";
}

int main()
{
	//ifstream cin("test.txt");
	string strin,strtp;	
	vector<string>::iterator it;
	while(cin>>strin  &&  strin != "#")
	{
		ss.insert(ss.end(),strin);
	}
	while(cin>>strin  && strin != "#")
	{
		if(find(ss,strin) < 10000000)
		{
			cout<<strin<<" is correct\n";
		}
		else
		{
			cout<<strin<<":";
			for(it = ss.begin();it!=ss.end();it++)
			{
				strtp = cmp(strin,*it);
				if(strtp != "%%")
				{
					cout<<" "<<strtp;
				}
			}
			cout<<"\n";
		}
	}
	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