69,371
社区成员
发帖
与我相关
我的任务
分享
#include <stdio.h>
#define MAX 100
char graph[MAX][MAX];
char c;
int weigh, heigh;
void fill(int x,int y)
{
if (x < weigh && y < heigh && x >= 0 && y >= 0 && graph[y][x] != '+' && graph[y][x] != '|' && graph[y][x] != '-')
{
graph[y][x] = c;
fill(x+1,y);
fill(x-1,y);
fill(x,y+1);
fill(x,y-1);
}
}
int main()
{
int count, choice;
int x1, y1, x2, y2;
int x, y;
int i, j;
scanf("%d %d %d", &weigh, &heigh, &count);
for (i = 0; i < heigh; i++)
for (j = 0; j < weigh; j++)
graph[i][j] = '.';
while (count--)
{
scanf("%d", &choice);
switch (choice)
{
case 0:
scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
if (y1 == y2)
{
if (graph[y1][x1] == '|')
graph[y1][x1] = '+';
else
graph[y1][x1] = '-';
if (graph[y2][x2] == '|')
graph[y2][x2] = '+';
else
graph[y2][x2] = '-';
while ((++x1) != x2)
graph[y1][x1] = '-';
}
else if (x1 == x2)
{
if (graph[y1][x1] == '-')
graph[y1][x1] = '+';
else
graph[y1][x1] = '|';
if (graph[y2][x2] == '-')
graph[y2][x2] = '+';
else
graph[y2][x2] = '|';
while ((++y1) != y2)
graph[y1][x1] = '|';
}
break;
case 1:
scanf("%d %d %c", &x, &y, &c);
fill(x,y);
break;
}
}
for (i = 0; i < heigh; i++)
for (j = 0; j < weigh; j++)
{
if (j == weigh-1)
printf("%c\n", graph[i][j]);
else
printf("%c", graph[i][j]);
}
return 0;
}
#include <stdio.h>
#define MAX 100
char graph[MAX][MAX];
char c;
int weigh, heigh;
int visited[MAX][MAX];
void fill(int x,int y)
{
if (x < weigh && y < heigh && x >= 0 && y >= 0 && graph[y][x] != '+' && graph[y][x] != '|' && graph[y][x] != '-' && visited[y][x])
{
visited[y][x] = 0;
graph[y][x] = c;
fill(x+1,y);
fill(x-1,y);
fill(x,y+1);
fill(x,y-1);
}
}
int main()
{
int count, choice;
int x1, y1, x2, y2;
int x, y;
int i, j;
scanf("%d %d %d", &weigh, &heigh, &count);
for (i = 0; i < heigh; i++)
for (j = 0; j < weigh; j++)
{
graph[i][j] = '.';
visited[i][j] = 1;
}
while (count--)
{
scanf("%d", &choice);
switch (choice)
{
case 0:
scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
if (y1 == y2)
{
if (graph[y1][x1] == '|')
graph[y1][x1] = '+';
else
graph[y1][x1] = '-';
if (graph[y2][x2] == '|')
graph[y2][x2] = '+';
else
graph[y2][x2] = '-';
while ((++x1) != x2)
graph[y1][x1] = '-';
}
else if (x1 == x2)
{
if (graph[y1][x1] == '-')
graph[y1][x1] = '+';
else
graph[y1][x1] = '|';
if (graph[y2][x2] == '-')
graph[y2][x2] = '+';
else
graph[y2][x2] = '|';
while ((++y1) != y2)
graph[y1][x1] = '|';
}
break;
case 1:
scanf("%d %d %c", &x, &y, &c);
fill(x,y);
break;
}
}
for (i = 0; i < heigh; i++)
for (j = 0; j < weigh; j++)
{
if (j == weigh-1)
printf("%c\n", graph[i][j]);
else
printf("%c", graph[i][j]);
}
return 0;
}
CSDN保佑 一发上来就自己解决了 加了个visited[MAX][MAX]标志数组就好了