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

const int 跟#define的问题ce了两次,求0ms方法,附想法跟代码

Posted by Belldandy at 2013-10-09 17:05:32 on Problem 1099
想法就是为0的数重新标号,然后输出
#include<stdio.h>
#define NUM 11
int change(int i, int j, int left, int above)
{
	int ans=0;
	if(i==0)
	{
		if(0==j || 2 == left)
		{
			ans=2;
		}
		else
		{
			ans=3;
		}
	}
	else
	{
		if(0 == j)
		{
			if(-1 == above || 2== above|| 3==above)
			{
				ans=2;
			}
			else
			{
				ans=5;
			}
		}
		else
		{
			if(-1==above || 3==above || 2==above)
			{
				if(-1==left ||5==left ||2==left)
				{
					ans=2;
				}
				else
				{
					ans=3;
				}
			}
			else
			{
				if(-1==left ||5==left ||2==left)
				{
					ans=5;
				}
				else
				{
					ans=4;
				}
			}
		}
	}
	return ans;
}

void print(int data[NUM][NUM],int num,int n)
{
	int i=0,j=0,len=n-1;
	printf("Case %d:\n\n",num);
	for(i=0;i<4*n+3;++i)
	{
		putchar('*');
	}
	putchar('\n');
	for(i=0;i<len;++i)
	{
		putchar('*');
		putchar('H');
		for(j=0;j<n;++j)
		{
			if(1==data[i][j]||2==data[i][j]||5==data[i][j])
			{
				putchar('-');
			}
			else
			{
				putchar(' ');
			}
			putchar('O');
			if(1==data[i][j]||3==data[i][j]||4==data[i][j])
			{
				putchar('-');
			}
			else
			{
				putchar(' ');
			}
			putchar('H');
		}
		printf("*\n* ");
		for(j=0;j<n;++j)
		{
			if(-1==data[i][j]||2==data[i][j]||3==data[i][j])
			{
				printf(" |  ");
			}
			else
			{
				printf("    ");
			}
		}
		printf("*\n* ");
		for(j=0;j<n;++j)
		{
			printf(" H  ");
		}
		printf("*\n* ");
		for(j=0;j<n;++j)
		{
			if(1==data[i][j]||4==data[i][j]||5==data[i][j])
			{
				printf(" |  ");
			}
			else
			{
				printf("    ");
			}
		}
		printf("*\n");
	}
	printf("*H");
	for(j=0; j<n; ++j)
	{
		if(1==data[len][j]||2==data[len][j]||5==data[len][j])
		{
			putchar('-');
		}
		else
		{
			putchar(' ');
		}
		putchar('O');
		if(1==data[len][j]||3==data[len][j]||4==data[len][j])
		{
			putchar('-');
		}
		else
		{
			putchar(' ');
		}
		putchar('H');
	}
	printf("*\n");
	for(i=0;i<4*n+3;++i)
	{
		putchar('*');
	}
	putchar('\n');
	putchar('\n');
}
int main()
{
	int n=0,i=0,count=0,j=0,left=0,above=0;
	int data[NUM][NUM];
	while(scanf("%d",&n)&&n)
	{
		for(i=0; i<n; ++i)
		{
			for(j=0; j<n; ++j)
			{
				scanf("%d",data[i]+j);
				if(0==data[i][j])
				{
					if(0!=j)
					{
						left=data[i][j-1];
					}
					if(0!=i)
					{
						above=data[i-1][j];
					}
					data[i][j]=change(i,j,left,above);
				}
			}
		}
		print(data,++count,n);
	}
}

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