问题描述
解题思路
正常思路就好。
代码
class Solution {
public:
int getLucky(string s, int k) {
vector<int> num;
int tmp = 0;
int sum = 0;
for (char c : s) {
tmp = c - 'a' + 1;
if (tmp / 10) {
num.push_back(tmp / 10);
sum += tmp / 10;
}
num.push_back(tmp % 10);
sum += tmp % 10;
}
int res_sum = 0;
for (int i = 1; i < k; i++) {
while (sum != 0) {
res_sum += sum % 10;
sum = sum / 10;
}
sum = res_sum;
res_sum = 0;
}
return sum;
}
};
标签:digits,tmp,convert,string,10,int,res,sum,num
From: https://www.cnblogs.com/zwyyy456/p/16985805.html