https://leetcode.com/problems/sum-of-digits-of-string-after-convert/

Source


    int getLucky(string s, int k) {
        string strNums;
        FOR (i, s.length()) {
            const int n = s[i] - 'a' + 1;
            strNums += to_string(n);
        }
        int ans = 0;
        FOR (i, k) {
            int sum = 0;
            FOR (j, strNums.length()) {
                sum += strNums[j] - '0';
            }
            ans = sum;
            strNums = to_string(ans);
        }

        return ans;
    }

GitHub