You are on page 1of 2

#include <fstream>

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

ifstream fin("scytale.in");
ofstream fout("scytale.out");

int main()
{
int m, cer, l = 0, c = 0;

string s;
fin >> cer;
fin >> s;
fin >> m;

int n = s.length();
char** a = new char* [m];
for (int i = 0; i < m; i++) {
a[i] = new char[n];
for (int j = 0; j < n; j++)
a[i][j] = '0';
}

if (cer == 1)
{
for (int i = 0; i < n; i++)
{
a[l][c] = s[i];
c += m;
if (c >= n)
{
l++;
c = l;
}
}
l = c = 0;

for (int i = 0; i < n; i++)


{
fout << a[l][c];
if (l < m - 1)
{
l++;
c++;
}
else
{
l = 0;
c++;
}
}
}
else
{
for (int i = 0; i < n; i++)
{
a[l][c] = s[i];
if (l < m - 1)
{
l++;
}
else
{
l = 0;
c++;
}
}

for (int i = 0; i < m; i++)


for (int j = 0; j < n; j++)
if (a[i][j] != '0')
fout << a[i][j];
}
return 0;
}

You might also like