482. 密钥格式化
class Solution {
public:
string licenseKeyFormatting(string s, int k) {
string res;
for (int i = s.size() - 1, cnt = 0; i >= 0; i -- ) {
if (s[i] != '-') {
res.push_back(toupper(s[i]));
cnt ++ ;
if (cnt % k == 0) res += '-';
}
}
if (res.back() == '-') res.pop_back();
reverse(res.begin(), res.end());
return res;
}
};