t_lst_col *list_calc_cols(t_lst_item *items, t_lst_col *cols) { t_lst_col *col; int height; if ((height = ft_trmheight() - 1) <= 0) { ft_lstdel((t_lst **)&cols, NULL); return (NULL); } col = cols; while (items) { if (!col && (!(col = (t_lst_col *)ft_lstpushback__(sizeof(t_lst_col), (t_lst **)&cols)))) return (NULL); items = calc_col(col, items, height); if (!items && col->next) { ft_lstdel((t_lst **)&col->next, NULL); col->next = NULL; } col = col->next; } return (cols); }
int main() { prepare(); int T; scanf("%d", &T); int ncase = 0; while (T--) { scanf("%d", &N); for (int i = 1; i <= N; ++i) { int x, y; scanf("%d%d", &x, &y); pts[i] = Point(x, y); } calc_col(); printf("Case %d: %d\n", ++ncase, f(init_popcount(N))); } return 0; }
int main(int argc, char *argv[]) { char *one_ldr; /* output leader to use on first line */ char *dflt_ldr; /* output leader for subsequent lines */ char *fld_sep; /* selected field seperator */ char *curr_sep; /* text to output before next field */ int maxwid; /* maximum output line width */ int outb_col; /* current column pos in output rec */ int outb_len; /* current length of output record */ int i; extern int optind; extern char *optarg; /* * Initialize defaults. */ maxwid = MAXWID; one_ldr = ONE_LDR; dflt_ldr = DFLT_LDR; fld_sep = FLDSEP; /* * Crack command line. */ while ((i = getopt(argc, argv, "w:1:l:f:")) != EOF) { switch (i) { case 'w': maxwid = atoi(optarg); break; case '1': one_ldr = optarg; break; case 'l': dflt_ldr = optarg; break; case 'f': fld_sep = optarg; break; default: usage_error(argv[0]); } } if (optind != argc) usage_error(argv[0]); /* * Initialize output buffer. */ (void) strfcpy(outbuf, one_ldr, sizeof(outbuf)); outb_col = calc_col(0, one_ldr); outb_len = strlen(one_ldr); curr_sep = ""; /* * Process the input a line at a time. */ while (fgets(inbuf, sizeof(inbuf), stdin) != NULL) { /* * Trim trailing space. Skip blank lines. */ for (i = strlen(inbuf) - 1 ; i >= 0 && isspace(inbuf[i]) ; --i) ; inbuf[i+1] = '\0'; if (inbuf[0] == '\0') continue; /* * If this text exceeds the line length then print the stored * info and reset the line. */ if (calc_col(calc_col(outb_col, curr_sep), inbuf) >= maxwid) { printf("%s%s\n", outbuf, curr_sep); curr_sep = dflt_ldr; outb_col = 0; outb_len = 0; outbuf[0] = '\0'; } /* * Append the current field seperator to the stored info. */ (void) strfcpy(outbuf+outb_len, curr_sep, sizeof(outbuf)-outb_len); outb_col = calc_col(outb_col, outbuf+outb_len); outb_len += strlen(outbuf+outb_len); /* * Append the text to the stored info. */ (void) strfcpy(outbuf+outb_len, inbuf, sizeof(outbuf)-outb_len); outb_col = calc_col(outb_col, outbuf+outb_len); outb_len += strlen(outbuf+outb_len); /* * Enable the field seperator. */ curr_sep = fld_sep; } if (*outbuf != '\0') puts(outbuf); exit(0); }