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

无语,恨死我自己,不小心将几个大写P中的一个写成小写p,害我调试了半个小时!!!!!!!!!!!!

Posted by gfedcba at 2009-02-20 19:27:24 on Problem 2339 and last updated at 2009-02-20 19:39:58
#include <iostream>*
using namespace std;

const int N = 100;
char grid[N][N];
char newGrid[N][N];

void Place(int r, int c, int i, int j)
{
	
	if (grid[i][j] == 'R')
	{
		if (i-1>=0 && grid[i-1][j]=='P')
		{
			newGrid[i][j] = 'P';
		}
		if (i+1<=r-1 && grid[i+1][j]=='P') // 就是这个大写的P,被我不小心写成小写p!!!!!!
		{
			newGrid[i][j] = 'P';
		}
		if (j-1>=0 && grid[i][j-1]=='P')
		{
			newGrid[i][j] = 'P';
		}
		if (j+1<=c-1 && grid[i][j+1]=='P')
		{
			newGrid[i][j] = 'P';
		}

	}
	if (grid[i][j] == 'S')
	{
		if (i-1>=0 && grid[i-1][j]=='R')
		{
			newGrid[i][j] = 'R';
		}
		if (i+1<=r-1 && grid[i+1][j]=='R')
		{
			newGrid[i][j] = 'R';
		}
		if (j-1>=0 && grid[i][j-1]=='R')
		{
			newGrid[i][j] = 'R';
		}
		if (j+1<=c-1 && grid[i][j+1]=='R')
		{
			newGrid[i][j] = 'R';
		}
	}
	if (grid[i][j] == 'P')
	{
		if (i-1>=0 && grid[i-1][j]=='S')
		{
			newGrid[i][j] = 'S';
		}
		if (i+1<=r-1 && grid[i+1][j]=='S')
		{
			newGrid[i][j] = 'S';
		}
		if (j-1>=0 && grid[i][j-1]=='S')
		{
			newGrid[i][j] = 'S';
		}
		if (j+1<=c-1 && grid[i][j+1]=='S')
		{
			newGrid[i][j] = 'S';
		}
	}
}
int main()
{
    int i,j;
	int time;
	int r,c,n;
	cin>>time;
	while (time--)
	{
		cin>>r>>c>>n;
		for (i=0; i<=r-1; i++)
		{
			for (j=0; j<=c-1; j++)
			{
				cin>>grid[i][j];
				newGrid[i][j] = grid[i][j];
			}
		}
		
		
		while (n--)
		{
			for (i=0; i<=r-1; i++)
			{
				for (j=0; j<=c-1; j++)
				{
					Place(r, c, i, j);
				
				}
			}

			for (i=0; i<=r-1; i++)
			{
				for (j=0; j<=c-1; j++)
				{
					grid[i][j] = newGrid[i][j];
				}
			}
		}
		
		 
		for (i=0; i<=r-1; i++)
		{
			for (j=0; j<=c-1; j++)
			{
				cout<<grid[i][j];
			}
			cout<<endl;
		}
		cout<<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