Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

冒死贴个代码吧……

Posted by johnzhao at 2010-05-27 14:48:00 on Problem 3752
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator