-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDay83.cpp
More file actions
51 lines (24 loc) · 663 Bytes
/
Day83.cpp
File metadata and controls
51 lines (24 loc) · 663 Bytes
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
47
48
49
50
51
string ReFormatString(string S, int k){
vector <string> v;
string s;
for(int i = 0;i < S.size(); i++)
{
if(S[i] != '-')
s.push_back(S[i]);
}
transform (s.begin(), s.end(), s.begin(), :: toupper);
int cnt = 1;
string ans;
for(int i = s.size()-1; i>= 0; i--,cnt++)
{
if(cnt == k)
{
ans += s[i];
ans.push_back('-'),cnt = 0;
}
else ans += s[i];
}
reverse(ans.begin(),ans.end());
if(ans[0] == '-') return ans.substr(1,ans.size());
return ans;
}