# include # include # include # include # include using namespace std; # include "polyomino_index.hpp" //****************************************************************************80 int *polyomino_index ( int m, int n, int p[] ) //****************************************************************************80 // // Purpose: // // POLYOMINO_INDEX assigns an index to each nonzero entry of a polyomino. // // Example: // // P = // 1 0 1 1 // 1 1 1 0 // 0 1 1 0 // // PIN = // 1 0 2 3 // 4 5 6 0 // 0 7 8 0 // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 17 May 2018 // // Author: // // John Burkardt // // Parameters: // // Input, int M, N, the number of rows and columns in the array that // represents the polyomino. // // Input, int P[M*N], the polyomino. It is assumed that every entry // is a 0 or a 1. // // Output, int *PIN[M*N], the index of each nonzero entry. // { int i; int j; int k; int *pin; pin = new int[ m * n ]; k = 0; for ( i = 0; i < m; i++ ) { for ( j = 0; j < n; j++ ) { if ( p[i+j*m] != 0 ) { k = k + 1; pin[i+j*m] = k; } else { pin[i+j*m] = 0; } } } return pin; } //****************************************************************************80 void polyomino_print ( int m, int n, int p[], string label ) //****************************************************************************80 // // Purpose: // // POLYOMINO_PRINT prints a polyomino. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 29 April 2018 // // Author: // // John Burkardt // // Parameters: // // Input, int M, N, the number of rows and columns in the representation // of the polyomino P. // // Input, int P[M*N], a matrix of 0's and 1's representing the // polyomino. The matrix should be "tight", that is, there should be a // 1 in row 1, and in column 1, and in row M, and in column N. // // Input, string LABEL, a title for the polyomino. // { int i; int j; cout << "\n"; cout << label << "\n"; cout << "\n"; if ( m <= 0 || n <= 0 ) { cout << " [ Null matrix ]\n"; } else { for ( i = 0; i < m; i++ ) { for ( j = 0; j < n; j++ ) { cout << " " << p[i+j*m]; } cout << "\n"; } } return; } //****************************************************************************80 void timestamp ( ) //****************************************************************************80 // // Purpose: // // TIMESTAMP prints the current YMDHMS date as a time stamp. // // Example: // // 31 May 2001 09:45:54 AM // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 19 March 2018 // // Author: // // John Burkardt // // Parameters: // // None // { # define TIME_SIZE 40 static char time_buffer[TIME_SIZE]; const struct std::tm *tm_ptr; std::time_t now; now = std::time ( NULL ); tm_ptr = std::localtime ( &now ); std::strftime ( time_buffer, TIME_SIZE, "%d %B %Y %I:%M:%S %p", tm_ptr ); std::cout << time_buffer << "\n"; return; # undef TIME_SIZE }