美文网首页
POJ - 1068

POJ - 1068

作者: Poisson_Lee | 来源:发表于2019-08-18 09:27 被阅读0次
#include <stdio.h>

void TransPar(int num_q[], int num) {
    int Par_Q[41];
    int Par_V[41] = {0};
    int index = 0;
    for (int i = 0; i < num_q[0]; i++) {
        Par_Q[index] = 1;
        index++;
    }
    Par_Q[index] = 2;
    index++;
    for (int i = 1; i < num; i++) {
        for (int j = 0; j < num_q[i] - num_q[i - 1]; j++) {
            Par_Q[index] = 1;
            index++;
        }
        Par_Q[index] = 2;
        index++;
    }
    ////for (int i = 0; i < index; i++) {
    ////    printf("%d",Par_Q[i]);
    ////}

    for (int i = 0; i < index; i++) {
        int par_cnt = 1;
        if (Par_Q[i] == 2) {
            for (int j = i - 1; j >= 0; j--) {
                if (Par_Q[j] == 1) {
                    if(Par_V[j]){
                        par_cnt++;
                    }
                    else {
                        Par_V[j] = 1;
                        break;
                    }
                }
            }
            if (i < index - 1) {
                printf("%d ", par_cnt);
            }
            else {
                printf("%d", par_cnt);
            }
        }
    }
    printf("\n");
}

void main() {
    ////int num_q[] = { 4,6,6,6,6,8,9,9,9};
    ////TransPar(num_q, 9);
    int test_num;
    scanf("%d", &test_num);
    for (int i = 0; i < test_num; i++) {
        int num_i;
        int num_q[21];
        scanf("%d", &num_i);
        for (int j = 0; j < num_i; j++) {
            scanf("%d", &num_q[j]);
        }
        TransPar(num_q, num_i);

    }
    ///while (1) {
    /// getchar();
    ///}

}

相关文章

网友评论

      本文标题:POJ - 1068

      本文链接:https://www.haomeiwen.com/subject/wvtrsctx.html