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 zAaron at 2006-11-08 13:18:14 on Problem 3078
//p3078.cpp
//Problem B:Q 
//
#include <iostream>
#include <vector>
#include <string>
using namespace std;

struct item{
	string word;
	int pos;
};

vector<item> items;

int mn[21][2];
 
void Input()
{
	cin >> mn[0][0] >> mn[0][1];
	item a;
	for (int i=0; i<mn[0][0]; i++)
	{
		cin >> a.word;
		a.pos = i+1 ;
		items.push_back(a);	 
	}
 
	for (i=1; i<=mn[0][1]; i++)
		for (int j=0; j<2; j++)
		 	cin >> mn[i][j];  
}

void Output()
{
	for (int i=1; i<=mn[0][0]; i++)
		for (int j=0; j<mn[0][0]; j++)
			if (items[j].pos == i) 
			{  
				cout << items[j].word;
				if (i<mn[0][0]) cout<<' ';
				break;
			}
	cout << endl;
}


void Solve()
{	
	int flag,cnt1 = 0 , cnt2 = 1;
	for (int i=1; i<=mn[0][0]; i++)
	{
		flag=0;
		for (int j=1; j<=mn[0][1] && cnt1<=mn[0][1]; j++)
			if ( mn[j][1] == i ) { items[mn[j][0]-1].pos = i; flag=1; cnt1++;break;}
		
		if (flag == 0) 
		for (int k=cnt2; k<=mn[0][0]; k++)
		{
			flag = 0;
			for (int j=1; j<=mn[0][1]; j++)
				if (mn[j][0] == k) flag = 1;
			if (flag == 0)
			{ items[k-1].pos = i; cnt2++; break;}  
		}
	}	
}

int main()
{
	int nums;
	cin >> nums;
	while (nums--)
	{
		Input();
 		Solve();
 		Output();
		items.clear();
	}
	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