码迷,mamicode.com
首页 > 其他好文 > 详细

UVALive 6451:Tables(模拟 Grade D)

时间:2014-10-02 17:53:33      阅读:146      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   io   ar   for   sp   div   

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;
}

 

UVALive 6451:Tables(模拟 Grade D)

标签:style   blog   http   color   io   ar   for   sp   div   

原文地址:http://www.cnblogs.com/shinecheng/p/4004174.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!