Simple Solution | Math | C++
Approach\n Describe your approach to solving the problem. \nJust calculate the position of character in order to add to the result. Besides, it\'s necessary to 
# Approach\n<!-- Describe your approach to solving the problem. -->\nJust calculate the position of character in order to add to the result. Besides, it\'s necessary to specify the limit of the next `rows` to avoid misalignment.\n\nThe position of the current character need to be added to `s`:\n*-* Calculation `i + j * (cols + 1)`.\n*-* `i` is the starting position of the next character in the first row.\n*-* `j * cols` is the first position of each row.\n*-* `j` is the increase of the position column relative to position `i` after each subsequent row.\n\nThe limit position of each row is `cols * (j + 1)`, i.e. the first position of the next row. When the calculated position exceeds the limit position of the current row, this loop ends.\n# Complexity\n- Time complexity: $$O(n)$$ with n is `encodedText.length`\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(1)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    string decodeCiphertext(string encodedText, int rows) {\n        // Initialize an empty string\n        string s = "";\n        //\n        int len = encodedText.length(), cols = len/rows;\n        //\n        for(int i = 0; i < cols; i++) {\n            //\n            for(int j = 0; j < rows; j++) {\n                // Calculate the position of the current character\n                int pos = i + j * (cols + 1), lim = cols * (j + 1);\n                //\n                if(pos < lim) s += encodedText[pos]; else break;\n            }\n        }\n        // Post-processing of the space character at the end of string\n        int k;\n        //\n        for(k = s.length() - 1; k > -1; k--) if(s[k] != \' \') break;\n        //\n        return s.substr(0, k + 1);\n    }\n};\n```
['Math', 'C++']