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

WA两天了, 不知道错哪了,谁能帮忙看看  ?

Posted by nuciedh at 2007-08-16 12:51:08 on Problem 3344
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

char c[9][9];
int state, x, y;
bool canmove;

void print ()
{
    int i, j;
    for (i = 1; i <= 8; i ++)
    {
        for (j = 0; j < 8; j ++)
        {
            printf ("%c", c[i][j]);
        }
        printf ("\n");
    }
}

void move ()
{
    char a[10], b[10], t[20];
    int step, i, j, m, id;
    scanf ("%s", a);
    
    while (a[0] != '#')
    {
        if (strcmp(a, "move") == 0)
        {
            scanf ("%d", &step);
            
            if (step > 8) step = 8;
            m = step;
            if (m)
            {
                if (state == 0)
                {
                    for (i = 1; i <= m; i ++)
                    {
                        id = y + i;
                        for (j = id; j < 8; j ++)
                        if (c[x][j] == '.') break;
                        for (; j > id; j --)
                        c[x][j] = c[x][j - 1], c[x][j - 1] = '.';
                        
                    }
                    c[x][8] = '\0';
                    y += step;
                    if (y > 7) y = 7;
                }
                else if (state == 1)
                {
                    for (i = 1; i <= m; i ++)
                    {
                        id = x + i;
                        for (j = id; j < 9; j ++)
                        if (c[j][y] == '.') break;
                        for (; j > id; j --)
                        c[j][y] = c[j - 1][y], c[j - 1][y] = '.';
                    }
                    x += step;
                    if (x > 8) x = 8;
                }
                else if (state == 2)
                {
                    for (i = 1; i <= m; i ++)
                    {
                        id = y - i;
                        for (j = id; j >= 0; j --)
                        if (c[x][j] == '.') break;
                        for (; j > id; j ++)
                        {
                            if (j == -1)
                            {
                                c[x][j + 1] = '.';
                                continue;
                            }
                            c[x][j] = c[x][j + 1], c[x][j + 1] = '.';
                        }
                    }
                    y -= step;
                    if (y < 0) y = 0;
                }
                else
                {
                    for (i = 1; i <= m; i ++)
                    {
                        id = x - i;
                        for (j = id; j >= 0; j --)
                        if (c[j][y] == '.') break;
                        for (; j < id; j ++)
                        {
                            if (j == -1)
                            {
                                c[j + 1][y] = '.';
                            }
                            c[j][y] = c[j + 1][y], c[j + 1][y] == '.';
                        }
                    }
                    x -= step;
                    if (x < 0) x = 0;
                }
            }
        }
        else
        {
            scanf ("%s", b);
            if (strcmp(b, "right") == 0)
            {
                state += 1;
                if (state > 3) state = 0;
            }
            else if (strcmp (b, "left") == 0)
            {
                state -= 1;
                if (state < 0) state = 3;
            }
            else
            {
                if (state == 0) state = 2;
                else if (state == 1) state = 3;
                else if (state == 2) state = 0;
                else if (state == 3) state = 1;
            }
        }
        scanf ("%s", a);
    }
}

void solve ()
{
    int i, j;
    for (i = 2; i < 9; i ++)
    scanf ("%s", c[i]);
    canmove = true;
    x = y = -1;
    for (i = 1; i < 9; i ++)
    {
        for (j = 0; j < 8 && x < 0; j ++)
        {
            if (c[i][j] == '>')
            {
                x = i; y = j;
                state = 0;
                c[i][j] = '.';
            }
            else if (c[i][j] == 'v')
            {
                x = i; y = j;
                state = 1;
                c[i][j] = '.';
            }
            else if (c[i][j] == '<')
            {
                x = i; y = j;
                state = 2;
                c[i][j] = '.';
            }
            else if (c[i][j] == '^')
            {
                x = i; y = j;
                state = 3;
                c[i][j] = '.';
            }
        }
    }
    move ();
    if (state == 0) c[x][y] = '>';
    else if (state == 1) c[x][y] = 'v';
    else if (state == 2) c[x][y] = '<';
    else c[x][y] = '^';
    print ();
    printf ("\n");
}

int main ()
{
    while (EOF != scanf ("%s", c[1]), c[1][0] != '-')
    solve ();
    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