-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathleetcode_482
46 lines (44 loc) · 1.01 KB
/
leetcode_482
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
class Solution {
public:
string licenseKeyFormatting(string S, int K) {
int len=S.size();
string tmp_ans="";
int i=len-1;
while(i>=0)
{
int j=0;
while(j<K&&i>=0)
{
if(S[i]=='-')//忽略破折号
i--;
else
{
if(S[i]>='a'&&S[i]<='z')//小写字母变大写
{
tmp_ans+=S[i]-'a'+'A';
}
else
{
tmp_ans+=S[i];
}
i--;
j++;
}
}
tmp_ans+='-';
}
string ans="";
cout<<tmp_ans<<endl;
i=tmp_ans.size()-1;
while(i>=0&&tmp_ans[i]=='-')
{
i--;
}
while(i>=0)
{
ans+=tmp_ans[i];
i--;
}
return ans;
}
};