Skip to content

Instantly share code, notes, and snippets.

@brycetsao
Created July 13, 2016 09:11
Show Gist options
  • Save brycetsao/5f7e95a5883267000802449ab51776cb to your computer and use it in GitHub Desktop.
Save brycetsao/5f7e95a5883267000802449ab51776cb to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
bool vis[10][10] = {};
char table[20][30];
int n, W;
/*
void test()
{
for(int i = 0; i < 10; ++i)
{
for(int j = 0; j < 10; ++j)
{
cout << vis[i][j];
}
cout << endl;
}
cout << endl;
}
*/
void fill(int h, int w, bool first)
{
for(int i = 0; i < 9; ++i)
{
for(int j = 0; first || j < W; ++j)
{
if(!vis[i][j])
{
for(int di = 0; di < h; ++di)
{
for(int dj = 0; dj < w; ++dj)
{
vis[i + di][j + dj] = true;
}
}
table[2 * i + 1][3 * j + 1] = '0' + i + 1;
table[2 * i + 1][3 * j + 2] = '0' + j + 1;
for(int di = 0; di < h; ++di)
{
table[2 * (i + di) + 1][3 * j] = '|';
}
for(int dj = 0; dj < w; ++dj)
{
table[2 * i][3 * (j + dj) + 1] = table[2 * i][3 * (j + dj) + 2] = '-';
}
return;
}
}
}
}
void print()
{
for(int x = 0; vis[x >> 1][0]; ++x)
{
for(int y = 0; y < 3 * W; ++y)
{
cout << table[x][y];
}
if(x & 1) cout << '|';
cout << endl;
}
for(int j = 0; j < W; ++j)
{
cout << " --";
}
cout << endl;
}
int main(int argc, char const *argv[])
{
while(cin >> n && n)
{
W = 0;
for(int i = 0; i < 20; ++i) fill_n(table[i], 30, ' ');
for(int i = 0; i < 30; ++i) fill_n(vis[i], 10, false);
for(int i = 0; i < n; ++i)
{
int m;
cin >> m;
for(int j = 0; j < m; ++j)
{
int h, w;
cin >> h >> w;
fill(h, w, !i);
//test();
if(!i) W += w;
}
}
print();
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment