需要注意的是每行最后一个之后没有空格。
#include <iostream>
#include <sstream>
#include <string>
#include <cstring>
#include <vector>
using namespace std;
int space[250];
int n;
vector<string> li[1200];
void printspace(int c)
{
for(int i = 0; i < c; i++)
cout << ' ';
}
int main()
{
// freopen("1593.txt", "r", stdin);
memset(space, -1, sizeof(space));
n = 0;
int i = 0, j, num = -1;
string str, line;
while(getline(cin, line))
{
stringstream trans(line);
while(trans >> str)
{
space[i] = space[i] < (int)str.length() ? (int)str.length() : space[i];
i++;
li[n].push_back(str);
}
n++;
i = 0;
}
for(i = 0; i < n; i++)
{
int size = li[i].size();
for(j = 0; j < size - 1; j++)
{
cout << li[i][j];
printspace(space[j] - li[i][j].length() + 1);
}
if(size != 0)
cout << li[i][j] << endl;
else
cout << endl;
}
return 0;
}