Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
一次AC,虽然写了很久,把==写成=号了,吐血了#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator