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

一次AC,虽然写了很久,把==写成=号了,吐血了

Posted by TSERROF at 2012-08-31 17:48:34 on Problem 3752
#include <cstdio>
int direction[4][2]={{1,0},{0,-1},{-1,0},{0,1}};
int main()
{
	int row,col;
	while(scanf("%d%d",&row,&col)!=EOF)
	{
		char **alpha=new char*[row];
		for(int i=0;i!=row;++i)
			alpha[i]=new char[col];
		int cnt=0,r_row=col,r_col=row,d_row=1,d_col=1,flag=1;
		int di=0,dj=0;
		while(cnt<row*col)
		{
			if(flag%2!=0)
			{
				int stop=r_row;
				--r_col;
				if(d_row%2!=0)
				{				
					while(stop--)
					{
						alpha[di][dj++]='A'+(cnt%26);
						++cnt;
						if(cnt==row*col)break;
					}
					--dj;
				}
				else
				{
					while(stop--)
					{
						alpha[di][dj--]='A'+(cnt%26);
						++cnt;
						if(cnt==row*col)break;
					}
					++dj;
				}
				++d_row;
			}
			else 
			{
				int stop=r_col;
				--r_row;
				if(d_col%2!=0)
				{
					while(stop--)
					{
						alpha[di++][dj]='A'+(cnt%26);
						cnt++;
						if(cnt==row*col)break;
					}
					--di;
				}
				else
				{
					while(stop--)
					{
						alpha[di--][dj]='A'+(cnt%26);
						++cnt;
						if(cnt==row*col)break;
					}
					++di;
				}
				++d_col;
			}		
			di+=direction[(flag-1)%4][0];
			dj+=direction[(flag-1)%4][1];
			++flag;
		}
		for(int i=0;i!=row;++i)
		{
			for(int j=0;j<col;++j)
			{
				printf("   %c",alpha[i][j]);
				if(j==col-1)printf("\n");
			}
		}
//		for(int i=0;i!=row;++i)
//			delete[]alpha;
//		delete []alpha;

//		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