482. License Key Formatting
class Solution {
public:
string licenseKeyFormatting(string S, int K) {
string res;
for (int i = S.size() - 1; i >= 0; i--)
if (S[i] != '-') {
if (res.size() % (K + 1) == K) res += '-';
res += toupper(S[i]);
}
reverse(res.begin(), res.end());
return res;
}
};