UVa give me fouth Runtime Error!
Can you help me?
#include <iostream>
using namespace std;
char cmd[100], tmp;
char board[251][251];
int col, row;
char color, tmpColor;
void Go(int x, int y)
{
board[y][x] = color;
if(y > 1 && board[y-1][x] == tmpColor) Go(x, y-1);
if(y < row && board[y+1][x] == tmpColor) Go(x, y+1);
if(x > 1 && board[y][x-1] == tmpColor) Go(x-1, y);
if(x < col && board[y][x+1] == tmpColor) Go(x+1, y);
}
int main()
{
while(true) {
gets(cmd);
if('X' == cmd[0]) break;
if('I' == cmd[0]) {
sscanf(cmd, "%c%d%d", &tmp, &col, &row);
for(int i = 1; i <= row; i++) {
for(int j = 1; j <= col; j++)
board[i][j] = 'O';
}
} else if('C' == cmd[0]) {
for(int i = 1; i <= row; i++) {
for(int j = 1; j <= col; j++)
board[i][j] = 'O';
}
} else if('L' == cmd[0]) {
int x, y;
sscanf(cmd, "%c%d%d %c", &tmp, &x, &y, &color);
board[y][x] = color;
} else if('V' == cmd[0]) {
int x, y1, y2;
sscanf(cmd, "%c%d%d%d %c", &tmp, &x, &y1, &y2, &color);
for(int i = y1; i <= y2; i++) {
board[i][x] = color;
}
} else if('H' == cmd[0]) {
int x1, x2, y;
sscanf(cmd, "%c%d%d%d %c", &tmp, &x1, &x2, &y, &color);
for(int i = x1; i <= x2; i++) {
board[y][i] = color;
}
} else if('K' == cmd[0]) {
int x1, x2, y1, y2;
sscanf(cmd, "%c%d%d%d%d %c", &tmp, &x1, &y1, &x2, &y2, &color);
for(int i = y1; i <= y2; i++) {
for(int j = x1; j <= x2; j++)
board[i][j] = color;
}
} else if('F' == cmd[0]) {
int x, y;
sscanf(cmd, "%c%d%d %c", &tmp, &x, &y, &color);
tmpColor = board[y][x];
Go(x, y);
} else if('S' == cmd[0]) {
char name[100];
sscanf(cmd, "%c%s", &tmp, name);
printf("%s\n", name);
for(int i = 1; i <= row; i++) {
for(int j = 1; j <= col; j++)
printf("%c", board[i][j]);
printf("\n");
}
}
}
return 0;
}
回复 更多评论