UVALive 6451:Tables(模拟 Grade D)

VJ题目链接

题意:模拟输出表格

思路:模拟……很暴力

代码:

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
using namespace std;

int graph[100][100];

int main() {
    int n;
    while (scanf("%d", &n) != EOF) {
        if (n == 0) break;
        memset(graph, 0, sizeof(graph));

        int maxcol = 0;
        for (int i = 0; i < n; i++){
            int m;
            scanf("%d", &m);
            for (int j = 0; j < m; j++) {
                int row, col;
                scanf("%d%d", &row, &col);
                int bgc = 0;
                while (graph[i][bgc] != 0) bgc++;
                col = bgc+col;
                row = i+row;
                int id = (i+1)*10+bgc+1;
                maxcol = max(maxcol, col);
                for (int r = i; r < row; r++) {
                    for (int c = bgc; c < col; c++) {
                        graph[r][c] = id;
                    }
                }
            }
        }

        //for (int i = 0; i < n; i++) {
        //    for (int j = 0; j < maxcol; j++) {
        //        printf("%d ", graph[i][j]);
        //    }puts("");
        //}puts("");

        for (int i = 0; i < maxcol; i++) {
            printf(" --");
        }puts("");

        for (int i = 0; graph[i][0]; i++) {
            //Line
            printf("|");
            for (int j = 0; graph[i][j]; j++) {
                if (graph[i][j] == (i+1)*10+j+1) printf("%d", graph[i][j]);
                else printf("  ");
                if (graph[i][j] == graph[i][j+1]) printf(" ");
                else printf("|");
            }puts("");

            //Button
            int store = 0;
            for (int j = 0; graph[i][j]; j++) {
                if (graph[i][j] == graph[i+1][j]) store++;
                else {
                    while (store) {
                        printf("   ");
                        store--;
                    }
                    printf(" --");
                }
            }puts("");
        }
        puts("");
    }
    return 0;
}

 

posted on 2014-10-02 16:05  ShineCheng  阅读(184)  评论(0编辑  收藏  举报

导航