链接:https://leetcode-cn.com/problems/license-key-formatting/
C++代码:
class Solution {
public:
string licenseKeyFormatting(string S, int K) {
string str = "";
for(int i = 0;i<S.size();i++)
{
if(S[i]!='-')
{
if(S[i]>='a'&&S[i]<='z')
str+=(char)S[i]-32;
else
str+=S[i];
}
}
string res= "";
int reminder = str.size()%K;
if(reminder!=0)
{
res+=str.substr(0,reminder);
res+='-';
}
for(int i = 0;i<str.size()/K;i++)
{
res+=str.substr(reminder+K*i,K);
res+='-';
}
res = res.substr(0,res.size()-1);
return res;
}
};
这篇博客主要讨论了LeetCode上的第482题,即如何对输入的许可证密钥进行格式化处理。通过C++代码展示了实现该功能的方法。
585

被折叠的 条评论
为什么被折叠?



