2075.cpp (452B)
1 class Solution { 2 public: 3 string decodeCiphertext(const string &encodedText, int rows) const { 4 const int col = size(encodedText) / rows; 5 string res; 6 7 for (int i = 0; i < col; i++) { 8 for (int j = i; j < size(encodedText); j += (col + 1)) { 9 res += encodedText[j]; 10 } 11 } 12 13 while (!res.empty() && res.back() == ' ') 14 res.pop_back(); 15 16 return res; 17 } 18 };