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 |
纯模拟 140K 0MS#include<cstdio> #include<cstring> #include<cctype> using namespace std; const char a[27]="ABCDEFGHIJKLMNOPQRSTUVWXYZ"; int main() { int n,m; scanf("%d%d",&n,&m); char s[100][100],d='E'; int o=-1,x=1,y=0,f=0; memset(s,' ',sizeof(s)); for (int i=1;i<=n*m;i++) { switch (d) { case 'W':s[x][--y]=a[(++o)%26]; break; case 'S':s[++x][y]=a[(++o)%26]; break; case 'E':s[x][++y]=a[(++o)%26]; break; case 'N':s[--x][y]=a[(++o)%26]; break; } if (x==f+1&&y==1+f) f++; if (d=='S'&&(isupper(s[x+1][y])||x==n)) d='W'; if (d=='E'&&(isupper(s[x][y+1])||y==m)) d='S'; if (d=='N'&&(isupper(s[x-1][y])||x==1)) d='E'; if (d=='W'&&(isupper(s[x][y-1])||y==1)) d='N'; } for (int i=1;i<=n;i++) { for (int j=1;j<=m;j++) printf(" %c",s[i][j]); printf("\n"); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator