-
Notifications
You must be signed in to change notification settings - Fork 476
Expand file tree
/
Copy path1324.cpp
More file actions
30 lines (27 loc) · 723 Bytes
/
1324.cpp
File metadata and controls
30 lines (27 loc) · 723 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
class Solution
{
public:
vector<string> printVertically(string s)
{
stringstream ss(s);
vector<string> strs;
string str;
while (ss >> str) strs.push_back(str);
int max_len = 0;
for (string& st : strs) max_len = max(max_len, (int)st.size());
vector<string> res(max_len);
for (int j = 0; j < max_len; j++)
{
for (string& st : strs)
{
if (st.size() > j) res[j] += st[j];
else res[j] += " ";
}
}
for (string& st : res)
{
while (!st.empty() && st.back() == ' ') st.pop_back();
}
return res;
}
};