UVA - 1593 Alignment of Code
2017-09-02 14:45
281 查看
/* 这题的收获 or 技巧 or 注意点 or 说明 1. getline函数读取整行 2. 流输入stringstream 3. string的size函数、length函数的返回类型都是size_type类型,在使用返回值之前,务必先进行强制类型转换 4. 此题有个坑点,每行的最后一列的单词,后面是没有空行的,直接回车,因此,要将最后一列的输出单独拿出来处理,而其他的就可以一起在循环里输出了 5. 这题可以运用C++输入输出的格式控制,不过也可以不用,直接循环输出也行,solve()1和solve2()函数任意调用一个,都可AC */
#include <bits/stdc++.h> using namespace std; const int maxn = 1005; const int maxm = 200; vector<string> a[maxn]; int len[maxm]; int row, col; void solve1(); void solve2(); int main() { string s, str; row = col = 0; while (getline(cin, str)) { stringstream ss(str); while (ss >> s) { len[col] = max(len[col], (int)s.size()); a[row].push_back(s); col++; } row++; col = 0; } // solve1(); solve2(); return 0; } void solve1() { int i, j; cout << setiosflags(ios::left); for (i = 0; i < row; i++) { for (j = 0; j < (int)a[i].size() - 1; j++) cout << setw(len[j] + 1) << a[i][j]; cout << a[i][j] << endl; } } void solve2() { int i, j, k; for (i = 0; i < row; i++) { for (j = 0; j < (int)a[i].size() - 1; j++) { for ( k = 0; k < (int)a[i][j].size(); k++) cout << a[i][j][k]; for (k = 0; k <= len[j] - (int)a[i][j].size(); k++) cout << ' '; } cout << a[i][j] << endl; } }
相关文章推荐
- UVa 1593 - Alignment of Code
- UVA - 1593 Alignment of Code(熟练c++操作)
- UVa 1593 - Alignment of Code
- UVa - 1593 Alignment of Code(自定义字符串流)
- UVA 1593 Alignment of Code
- UVa 1593 - Alignment of Code
- UVa1593 Alignment of Code
- UVa 1593 Alignment of Code(字符串)
- UVa-1593 - Alignment of Code
- Uva1593 - Alignment of Code(getline、istringstream用法)
- UVa 1593 Alignment of Code
- Uva - 1593 - Alignment of Code
- Alignment of Code UVA - 1593(水题)
- Problem 043——UVa 1593 - Alignment of Code
- UVA_1593: Alignment of Code
- UVa 1593 Alignment of Code
- UVa 1593 Alignment of Code
- Uva - 1593 - Alignment of Code
- UVA 1593 Alignment of Code
- UVA - 1593 Alignment of Code