-
Notifications
You must be signed in to change notification settings - Fork 3
/
Day-43
35 lines (34 loc) · 859 Bytes
/
Day-43
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
string convert(string s, int n) {
//code
if(n == 1)
return s;
map<int,string> mp;
string res = "";
for(int i = 0; i < n ; i ++){
mp[i] = "";
}
int i = 0;
int j = 0;
while(i < s.length()){
while(j <= n - 1 and i < s.length()){
string t = mp[j];
t += s[i];
mp[j] = t;
if(j == n - 1) break;
j++;i++;
}
j--;i++;
while(j >= 0 and i < s.length()){
string t = mp[j];
t += s[i];
mp[j] = t;
if(j == 0) break;
j--;i++;
}
j++;i++;
}
for(auto i : mp){
res += i.second;
}
return res;
}