1642

来源:互联网 发布:浙江铁笼沉尸 知乎 编辑:程序博客网 时间:2024/06/10 14:43
#include <iostream>using namespace std;int stack[21][21], n, left_[21][21], right_[21][21];void input(){memset(stack, 0, sizeof(stack));for(int i = 0; i < n; ++i){int j = 0;cin >> stack[i][0];for(; stack[i][j] != 0; ++j){cin >> stack[i][j + 1];}}}void cal_left(const int (&s)[21][21], int(&l)[21][21]){int inner[21][21] = {0};memset(l, 0, sizeof(l));memcpy(inner, s, sizeof(inner));for(int row = 0; true; ++row){if(0 == inner[0][0]){break;}for(int col = 0; inner[col][0]; ++col){int acc = 0;for(; inner[col][acc] != 0; ++acc);l[row][col] = acc;}for(int i = 0; true; ++i){if(0 == inner[i][0]){break;}for(int j = 0; inner[i][j] != 0; ++j){--inner[i][j];}}}}void output(const int (&out)[21][21]){for(int i = 0; true; ++i){if(0 == out[i][0]){break;}cout << out[i][0];for(int j = 1; out[i][j] != 0; ++j){cout << ' ' << out[i][j];}cout << '\n';}}int main(){while(cin >> n, n){input();cal_left(stack, left_);output(left_);cout << '\n';cal_left(left_, right_);output(right_);cout << '\n' << '\n';}return 0;}