1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
|
#include <iostream>
using namespace std;
int sweep (int (&a)[5][5], int row, int column, int temp1, int temp2)
{
int countrow = temp1;
int countcolumn = temp2;
if (a[row][column] == 1)
{
a[row][column] = 0;
if (row < temp1+1)
{
countrow++;
sweep (a, countrow, column, temp1, temp2);
}
else if (row > temp1-1)
{
countrow--;
sweep (a, countrow, column, temp1, temp2);
}
if (column < temp2+1)
{
countcolumn++;
sweep (a, row, countcolumn, temp1, temp2);
}
else if (column > temp2-1)
{
countcolumn--;
sweep (a, row, countcolumn, temp1, temp2);
}
}
}
int main(){
int row = 0;
int column = 0;
int temp1 = 0;
int temp2 = 0;
int a[5][5]={{0,0,0,0,0},
{0,1,1,1,0},
{0,1,1,1,0},
{0,0,1,0,1},
{0,0,1,0,0}};
cout << "Please enter row number." << endl;
cin >> row;
cout << "Please enter column number." << endl;
cin >> column;
temp1 = row;
temp2 = column;
sweep(a, row, column, temp1, temp2);
for (int i = 0; i < 5; i++)
{
cout << endl;
for (int j = 0; j < 5; j++)
{
cout << a[i][j];
}
}
}
|