[c++] only code
{:style="width:440px"}\n\n---\ncpp []\nclass Solution {\npublic:\n    vector<vector<char>> rotateTheBox(vector<vector<char>>& box) {\n\n        int m = box.size
![upVote.jpeg](https://assets.leetcode.com/users/images/70e7b31a-560c-462d-a8ac-6bb42e368057_1732345086.1207628.webp){:style="width:440px"}\n\n---\n```cpp []\nclass Solution {\npublic:\n    vector<vector<char>> rotateTheBox(vector<vector<char>>& box) {\n\n        int m = box.size();\n        int n = box[0].size();\n\n        vector<vector<char>> ans(n, vector<char>(m, \'.\'));\n        for (int i = 0; i < m; i++) {\n            int stones = 0;\n            for (int j = 0; j < n; j++) {\n                if (box[i][j] == \'#\')\n                    stones++;\n\n                if (box[i][j] == \'*\') {\n                    ans[j][m - 1 - i] = \'*\';\n                    if (stones)\n                        ans[j - stones][m - 1 - i] = \'#\';\n                    stones = 0;\n                }\n            }\n            if (stones && box[i][n - 1] != \'*\') {\n                ans[n - stones][m - 1 - i] = \'#\';\n            }\n        }\n\n        // for (auto it : ans) {\n        //     for (auto e : it)\n        //         cout << e << " ";\n        //     cout << endl;\n        // }\n\n        for (int i = 0; i < m; i++) {\n            bool flag = false;\n            for (int j = 0; j < n; j++) {\n                if (ans[j][i] == \'*\')\n                    flag = false;\n                if (flag) {\n                    ans[j][i] = \'#\';\n                }\n                if (ans[j][i] == \'#\') {\n                    flag = true;\n                }\n            }\n        }\n        return ans;\n    }\n};\n```
['Matrix', 'C++']