Steward
分享是一種喜悅、更是一種幸福
程式語言 - LeetCode - C++ - 482. License Key Formatting
題目:

解答:
class Solution {
public:
string licenseKeyFormatting(string s, int k) {
int cnt = 0;
int n = s.size();
string ans = "";
for (int i = n - 1; i >= 0; --i) {
if (s[i] == '-') {
continue;
}
if (cnt == k) {
ans += "-";
cnt = 0;
}
ans += toupper(s[i]);
cnt += 1;
}
reverse(ans.begin(), ans.end());
return ans;
}
};