C++ solution
\nclass Solution {\npublic:\n    string digitSum(string s, int k) {\n        while ((int) s.size() > k) {\n            int sum = 0;\n            string t = "";\
```\nclass Solution {\npublic:\n    string digitSum(string s, int k) {\n        while ((int) s.size() > k) {\n            int sum = 0;\n            string t = "";\n            int count = 0;\n            for (int i = 0; i < (int) s.size(); i++) {\n                sum += (s[i] - \'0\');\n                ++count;\n                if (count == k) {\n                    t += to_string(sum);\n                    sum = 0;\n                    count = 0;\n                }\n            }\n            if (count > 0) {\n                t += to_string(sum);\n            }\n            s = t;\n        }\n        return s;\n    }\n};\n```
[]