一:题目
二:上码
class Solution {
public:/**思路:1.设置一个while循环,循环的条件是s.length<=k2.while里面进行 1>:将字符串按k个进行拆分成个单个字符,并将其转换成数字,然后计算将计算结果再组成字符串 */string digitSum(string s, int k) {if (s.size() <= k) return s;while (1) {string str;int sum = 0;for (int i = 0; i < s.size(); i++) {sum += s[i] - '0';if ((i+1)%k == 0) {string str1 = to_string(sum);str += str1;sum = 0;}}if(s.size()%k!= 0) {string str1 = to_string(sum);str += str1;}s = str;if(s.size() <= k) break;}return s;}};