Вот пример матрицы целых чисел int A[9][19]; Вот пример работы с таким матрицами... Вот когда писал программу игры Сапер
| Код | #include <iostream> using namespace std;
int main() { char Pole[101][101]; int m = 0; int n = 0; int forOut = 0; while ( forOut != -1 ) { cin >> n >> m; if ( (n == 0) && (m==0) ) forOut = -1; else { if ( forOut != 0 ) cout << endl; // init. of array if ( (n == 100) || ( m == 100 ) ) { for( int i = 1; i <= n; i++ ) for (int j = 1; j <= m; j++) Pole[i][j] = 0; } else { for( int i = 1; i <= n+1; i++ ) for (int j = 1; j <= m+1; j++) Pole[i][j] = 0; }
// enter array for( int i = 1; i <= n; i++ ) for (int j = 1; j <= m; j++) cin >> Pole[i][j] ; /*Algorithm*/ for( int row = 1; row <= n; row++) for ( int col = 1; col <= m; col++) if ( Pole[row][col] != '*' ) { int k = 0; if ( Pole[row-1][col-1] == '*' ) k++; if ( Pole[row-1][col] == '*' ) k++; if ( Pole[row-1][col+1] == '*' ) k++; if ( Pole[row][col-1] == '*' ) k++; if ( Pole[row][col+1] == '*' ) k++; if ( Pole[row+1][col-1] == '*' ) k++; if ( Pole[row+1][col] == '*' ) k++; if ( Pole[row+1][col+1] == '*' ) k++; Pole[row][col] = k + '0' ; } cout << "Field #" << ++forOut << ":" << endl; // write our array for( int i = 1; i <= n ; i++ ) { for ( int j = 1; j <= m ; j++ ) { if ( Pole[i][j] == '.' ) Pole[i][j] = '0'; cout << Pole[i][j] /*<< " "*/; } cout << endl; } //cout << endl ; } }
//system("PAUSE");
return 0; }
|
|