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> #include <stdlib.h> #include <mem.h> #define SIZE 100 int main () { char martix[SIZE][SIZE]; int M, N, i, j, next_i, next_j, x, ch, count; int direct[4][2] = {{1, 0},{0, 1},{-1, 0},{0, -1}}; while (scanf ("%d %d", &M, &N) != EOF) { i = j = next_i = next_j = x = ch = count = 0; memset (martix, ' ', sizeof (martix)); while (count < M * N) { martix[j][i] = 'A' + ch % 26; next_i = i + direct[x][0]; next_j = j + direct[x][1]; if (next_i == N || next_j == M || next_i < 0 || next_j < 0 || martix[next_j][next_i] != ' ') { x = (x + 1) % 4; next_i = i + direct[x][0]; next_j = j + direct[x][1]; } i = next_i; j = next_j; ch ++; count ++; } for (j = 0; j < M; j ++) { for (i = 0; i < N; i ++) printf ("%4c", martix[j][i]); 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