forked from kothariji/competitive-programming
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path(SPOJ) TOANDFRO - To and Fro.cpp
47 lines (46 loc) · 1015 Bytes
/
(SPOJ) TOANDFRO - To and Fro.cpp
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
#include <bits/stdc++.h>
using namespace std;
int main()
{
int col;
string s;
while (1)
{
cin >> col;
if (col == 0)
break;
cin >> s;
int len = s.length();
int row = len / col;
char a[row][col];
bool toggle = true;
int index = 0;
for (int i = 0; i < row; i++)
{
if (toggle)
for (int j = 0; j < col; j++)
{
a[i][j] = s[index];
toggle = false;
index++;
}
else
{
for (int j = col - 1; j > -1; j--)
{
a[i][j] = s[index];
toggle = true;
index++;
}
}
}
for (int i = 0; i < col; i++)
{
for (int j = 0; j < row; j++)
{
cout << a[j][i];
}
}
cout<<endl;
}
}