From 4734ada571465beea7af0f252b791d2f495c1219 Mon Sep 17 00:00:00 2001 From: KiritoTRw <3021577574@qq.com> Date: Thu, 28 Apr 2016 08:58:10 +0800 Subject: [PATCH] Create 1227.c --- QUSTOJ/1227.c | 118 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 118 insertions(+) create mode 100644 QUSTOJ/1227.c diff --git a/QUSTOJ/1227.c b/QUSTOJ/1227.c new file mode 100644 index 0000000..eaab5f3 --- /dev/null +++ b/QUSTOJ/1227.c @@ -0,0 +1,118 @@ +#include +#include +#include + +typedef struct +{ + char data; + int vis; +}pack; + +pack screen[102][102]; + +#define RIGHT 0 +#define DOWN 1 +#define LEFT 2 +#define UP 3 + +void deal(int incmax) +{ + memset(screen,0,sizeof(pack)*102*102); + char letter='A'; + int cx,cy,towards,i; + int times=incmax*incmax; + for(i=0;i0;times--) + { + screen[cx][cy].data=letter++; + screen[cx][cy].vis=1; + (letter>'Z')?(letter='A'):(NULL); + switch(towards) + { + case RIGHT: + { + if(screen[cx][cy+1].vis==1) + { + towards++; + cx++; + } + else + { + cy++; + } + break; + } + case DOWN: + { + if(screen[cx+1][cy].vis==1) + { + towards++; + cy--; + } + else + { + cx++; + } + break; + } + case LEFT: + { + if(screen[cx][cy-1].vis==1) + { + towards++; + cx--; + } + else + { + cy--; + } + break; + } + case UP: + { + if(screen[cx-1][cy].vis==1) + { + towards=0; + cy++; + } + else + { + cx--; + } + break; + } + } + } +} + +void print_map(int incmax) +{ + int x,y; + for(x=1;x0;all--) + { + scanf("%d",&inc); + deal(inc); + print_map(inc); + } + return 0; +}