0880.cpp (468B)
1 class Solution { 2 public: 3 string decodeAtIndex(const string &s, int k) { 4 long n = 0, idx; 5 6 for (idx = 0; n < k; idx++) { 7 n = isdigit(s[idx]) ? n * (s[idx] & 0x0F) : n + 1; 8 } 9 10 while (idx--) { 11 if (isdigit(s[idx])) 12 n /= s[idx] & 0x0F, k %= n; 13 else if (k % n == 0) 14 return string(1, s[idx]); 15 else 16 n--; 17 } 18 return ""; 19 } 20 };