To know the indentation of the first line, you need to know the number of lines in the input. Therefore, you must first read all the input. I decided to use a vector to store values ββfor the convenience of the .size () function, which will give the total number of lines after reading all the inputs.
#include<iostream>
In this example, I use setw to set the line width so that it is correctly justified. The filling in the left part of the line is set (sz - i), where sz is the total number of lines, and I is the current line. Therefore, each subsequent line has 1 less space on the left side.
Next, I need to add the original size of the string (string [i] .length ()), otherwise the string will not contain enough space for the resulting string to have the correct addition on the left side.
setw((sz - i) + lines[i].length())
Hope this helps!
source share