#include<vector>
#include<iostream>
#include<string>
#include<sstream>
using namespace std;
const int max_row = 1000;
void print(string s, int length)
{
int size = s.size();
for(int i = 0; i < size; i++)
cout << s[i];
for(int i = 0; i <= length - size; i++) //这里加=号是因为对齐完单词后还要空一列
cout << ' ';
}
int main()
{
vector<string> txt[max_row];
int col = 0, row = 0;
int max_len[180];
string t, tt;
while(getline(cin,t))
{
stringstream ss(t);
while(ss >> tt)
{
max_len[col] = max(max_len[col], (int)tt.size());
col++;
txt[row].push_back(tt);
}
col = 0;
row++;
}
for(int i = 0; i < row; i++)
{
int j = 0;
for(; j < txt[i].size() - 1; j++)
print(txt[i][j],max_len[j]);
cout << txt[i][j] << endl;
}
return 0;
}
代码对齐 UVa1593
最新推荐文章于 2020-09-21 17:33:49 发布