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 manchester__united at 2008-12-31 12:03:57 on Problem 1677
#include<iostream>
#include<string>
using namespace std;
int count(string wish,string name[],int g,int flag[],int& m,int& n)
{
	int count=0,i=0,j=0,k=0;
	for(i=0;i<wish.size();i++)
	{
		if(wish[i]>=65&&wish[i]<=90||wish[i]>=97&&wish[i]<=122)
		{
			for(j=i+1;j<wish.size();j++)
			{
				if(wish[j]>=65&&wish[j]<=90||wish[j]>=97&&wish[j]<=122)
				{
				}
				else
					break;
			}
			//cout<<wish.substr(i,j-i);
			count++;
			//cout<<wish.substr(i,j-i+1)<<endl;
			for(k=0;k<g;k++)
			{
				if(wish.substr(i,j-i)==name[k])
				{
					//cout<<name[k]<<endl;
					flag[k]=1;
					m=1;
				}
				if(wish.substr(i,j-i)=="beautiful"||wish.substr(i,j-i)=="pretty"||wish.substr(i,j-i)=="lovely")
					n=1;
			}
			i=j;
		}
	}
	return count;
}
			


void slove(string name[],string wish,int g)
{
	string temp;
	int flag[5]={0,0,0,0,0},i=0,j=0;
	int m=0,n=0;
	count(wish,name,g,flag,m,n);
	if(m==1)
	{
		for(i=0;i<g;i++)
		{
			if(flag[i]==1)
			{
				temp+=name[i];
				temp+=' ';
			}
		}
		temp[(temp.size())-1]=':';

		if(count(wish,name,g,flag,m,n)<10)
			cout<<temp<<" oh"<<endl;
			
		else if(n==1)
			cout<<temp<<" xixi"<<endl;
		else if(n==0)
			cout<<temp<<" hehe"<<endl;
		return;
		

	}
	else
	{
		temp="All: ";
		if(count(wish,name,g,flag,m,n)<10)
			cout<<temp<<"oh"<<endl;
		else if(n==1)
			cout<<temp<<"xixi"<<endl;
		else if(n==0)
			cout<<temp<<"hehe"<<endl;
		return;
	}
}

		

int main()
{
	int g,w,i,m=0,n=0;
	char c;
	cin>>g>>w;
	string name[5],wish[30];
	for(i=0;i<g;i++)
	{
		cin>>name[i];
	}
	getchar();
	for(i=0;i<w;i++)
	{
		while((c=getchar())!='\n')
			wish[i]+=c;
	}
	for(i=0;i<w;i++)
	{
		slove(name,wish[i],g);
		//cout<<wish[i]<<endl;
	}
	system("pause");
	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