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(代码内附c++,写的不好见谅)

Posted by problems at 2007-02-24 09:26:11 on Problem 1029
#include<iostream>
#include<memory>
using namespace std;
int main()
{
	char c;
	bool flag[1001];
	int light[1001],heavy[1001],n,k,pi,i,j,a[500],b[500],sum=0,num1=0;
	cin>>n>>k;
	memset(light,0,sizeof(light));
	memset(heavy,0,sizeof(heavy));
	for(i = 1 ; i <= n ; ++i) flag[i]=true;
	while(k != 0)
	{
		cin>>pi;
		for(i = 0 ; i != pi ; ++i) cin>>a[i];
		for(i = 0 ; i != pi ; ++i) cin>>b[i];
		cin>>c;
		if(c=='=')
		{
			for(i = 0 ; i != pi ; ++i)
			{
				flag[a[i]]=false;
				flag[b[i]]=false;
			}
		}
		if(c=='<')
		{
			++sum;
			for(i = 0 ; i != pi ; ++i)
			{
				++light[a[i]];
				++heavy[b[i]];
			}
		}
		if(c=='>')
		{
			++sum;
			for(i = 0 ; i != pi ; ++i)
			{
				++light[b[i]];
				++heavy[a[i]];
			}
		}
		--k;
	}
		if(sum==0)
		{
			for(i = 1 ; i != n ; ++i)
			{
				if(flag[i])
				{
					++num1;
					j=i;
				}
			}
			if(num1==1) cout<<j<<endl;
			else cout<<'0'<<endl;
		}
		else
		{
			for(i = 1 ; i != n ; ++i)
				if(flag[i] && ((light[i]==sum) || (heavy[i]==sum)))
				{
					++num1;
					j=i;
				}
			if(num1==1) cout<<j<<endl;
			else cout<<'0'<<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