#include #include char *data; int *offsets, data_size, file_size, offset_size, line_count, not_newline, max_width, width, c, r; int main() { while( (c = getchar()) != EOF ) { if( !not_newline ) { if( line_count + 2 > offset_size && !(offsets = (int*)realloc( offsets, sizeof(int) * (offset_size = offset_size ? offset_size * 2 : 64))) ) return -1; offsets[line_count++] = file_size; } not_newline = 0; if( c - 10 ) { if( file_size >= data_size && !(data = (char*)realloc( data, data_size = data_size ? data_size * 2 : 64)) ) return -1; data[file_size++] = c; not_newline = width = file_size - offsets[line_count - 1]; if( width > max_width ) max_width = width; } } offsets[line_count] = file_size; for(c = 0; c < max_width; putchar(10), c++) for(r = line_count; r-- > 0;) putchar(c >= (width = offsets[r + 1] - offsets[r]) ? 32 : data[offsets[r] + c]); return 0; }