您的位置:首页 > 其它

Uva - 1593 - Alignment of Code

2015-06-12 22:31 369 查看


直接用<iomanip>的格式输出,setw设置输出宽度,setiosflags(ios::left)进行左对齐。

AC代码:

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <stack>
#include <queue>
#include <iomanip>

using namespace std;

vector<string> s[1005];
int len[185];

int main()
{
string line, buf;
int i = 0, j = 0;
while (getline(cin, line)) {
istringstream stream(line);
while (stream >> buf) {
len[j] = max(len[j], (int)buf.length());
j++;
s[i].push_back(buf);
}
i++;
j = 0;
}
// 设置左对齐
cout << setiosflags(ios::left);
for (int k = 0; k < i; k++) {
int l = 0;
for (l; l < s[k].size() - 1; l++) {
// setw设置宽度
cout << setw(len[l] + 1) << s[k][l];
}
cout << s[k][l] << endl;
}

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: