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 |
求助改进!(提交一直提示超时)高手请不吝赐教... #include <stdio.h> int main() { int i, j, m, n, flag = 1; char letter[100][100], temp; enum { up = 0, down = 1, left = 2, right = 3 } direction; scanf("%d %d", &m, &n); for(i=0; i<m; i++) { for(j=0; j<n; j++) { letter[i][j] = 0; } } i = j = 0; temp = 0; letter[i][j] = 'A'; direction = 3; while(flag) { temp = letter[i][j]; switch(direction) { case 0: --i; if(i == -1 || letter[i][j] != 0) { ++i; direction = 3; } else { letter[i][j] = temp +1; if(letter[i][j] > 'Z') { letter[i][j] = 'A'; } } break; case 1: ++i; if(i == m || letter[i][j] != 0) { --i; direction = 2; } else { letter[i][j] = temp +1; if(letter[i][j] > 'Z') { letter[i][j] = 'A'; } } break; case 2: --j; if(j == -1 || letter[i][j] != 0) { ++j; direction = 0; } else { letter[i][j] = temp +1; if(letter[i][j] > 'Z') { letter[i][j] = 'A'; } } break; case 3: ++j; if(j == n || letter[i][j] != 0) { --j; direction = 1; } else { letter[i][j] = temp +1; if(letter[i][j] > 'Z') { letter[i][j] = 'A'; } } break; } if(letter[i+1][j] != 0 && letter[i][j+1] != 0 && letter[i-1][j] != 0 && letter[i][j-1] != 0) { flag = 0; } } for(i=0; i<m; i++) { for(j=0; j<n; j++) { if(j == n-1) { printf("%c\n", letter[i][j]); } else { printf("%c ", letter[i][j]); } } } return 1; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator