TOANDFRO - To and Fro Solution SPOJ - UCS - Unleash-Coding-Skills

## Tuesday, 17 April 2018

TOANDFRO - To and Fro
Link for Problem  TOANDFRO - To and Fro problem:

Problem:

### Input

There will be multiple input sets. Input for each set will consist of two lines. The first line will contain an integer in the range 2...20 indicating the number of columns used. The next line is a string of up to 200 lower case letters. The last input set is followed by a line containing a single 0, indicating end of input.

### Output

Each input set should generate one line of output, giving the original plaintext message, with no spaces.
```Input:

5
toioynnkpheleaigshareconhtomesnlewx
3
ttyohhieneesiaabss
0

Output:

theresnoplacelikehomeonasnowynightx
thisistheeasyoneab```
The CPP solution for this problem is

```#include <iostream>
#include <string>
using namespace std;

int main() {
int i,j,k,t,n,e;
string s;

while(1)
{
cin>>n;
if(n==0)
break;
cin>>s;
long int len=s.length();
char a[len/n][205];
e=0,k=0;
for(i=0;i<len;i++)
{
if(e==0)
{
for(j=0;j<n;j++)
{
a[k][j]=s[i];
i++;
}
k++;
e=1;
}
else
{
for(j=n-1;j>=0;j--)
{
a[k][j]=s[i];
i++;

}
k++;
e=0;
}
i--;
}

for(i=0;i<n;i++)
{
for(j=0;j<(len/n);j++)
cout<<a[j][i];
}
cout<<endl;

}
return 0;
}
```

Happy Coding.....