#include using namespace std; const int a_rows = 4; const int a_columns = 3; const int b_rows = 100; const int b_columns = 3; void compress_init(int a[][a_columns]) { for (int i = 0; i < a_rows; i++) for (int j = 0; j < a_columns; j++) cin >> a[i][j]; } void compress_process(int a[][a_columns], int b[][b_columns]) { b[0][0] = 4; b[0][1] = 3; b[0][2] = 0; for (int y = 0; y < 4; y++) { for (int x = 0; x < 3; x++) { if (a[y][x]) { b[++b[0][2]][0] = y; b[b[0][2]][1] = x; b[b[0][2]][2] = a[y][x]; } } } } void compress_print(int b[][b_columns]) { for (int y = 0; y <= b[0][2]; y++) { cout << b[y][0] << ' ' << b[y][1] << ' ' << b[y][2] << ' '; } } int main(int argc, char* argv[]) { int A[a_rows][a_columns], B[b_rows][b_columns]; compress_init(A); compress_process(A, B); compress_print(B); }