1class Solution {2public:3vector<string> printVertically(string s) {4int row = 0, col = 0;56stringstream sso(s);7string buffer;89while (sso >> buffer) {10row++;11col = max((int)buffer.size(), col);12}1314vector<vector<char>> matrix(row, vector<char>(col, ' '));1516sso = stringstream(s);1718int i = 0;19while (sso >> buffer) {20for (int j = 0; j < buffer.size(); j++) matrix[i][j] = buffer[j];21i++;22}2324vector<string> res;25for (int j = 0; j < col; j++) {26string item;27for (int i = 0; i < row; i++) item.push_back(matrix[i][j]);2829for (int i = item.size() - 1; i >= 0; i--) {30if (item[i] != ' ') {31item.erase(item.begin() + i + 1, item.end());32break;33}34}35res.push_back(item);36}3738return res;39}40};