迴圈
輸入 n m
輸入座標
判別橫向或縱向
將有畫到的設為false
一其規則輸出
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
int n, m;
int x[2], y[2], X, Y;
bool Bground[500][500];
int i, j;
while(cin >> n >> m)
{
memset(Bground, false, sizeof(Bground));
cin >> x[0] >> y[0];
for(i = 1; i<m; i++)
{
cin >> x[i%2] >> y[i%2];
if(x[i%2] == x[(i-1)%2])
{
X = x[i%2];
for(j = min(y[i%2], y[(i-1)%2]); j <= max(y[i%2], y[(i-1)%2] ); j++)
Bground[X-1][j-1] = true;
}
else
{
Y = y[i%2];
for(j = min(x[i%2], x[(i-1)%2]); j <= max(x[i%2], x[(i-1)%2]); j++)
Bground[j-1][Y-1] = true;
}
}
for(i = 0; i <= n+1; i++)
cout << "-";
cout << "\n";
for(i = 0; i<n; i++)
{
cout << "|";
for(j = 0; j<n; j++)
if(Bground[i][j])
cout << "*";
else
cout << " ";
cout << "|\n";
}
for(i = 0; i<=n+1; i++)
cout << "-";
cout << "\n";
}
return 0;
}
留言列表