Skip to content

Commit

Permalink
Merge pull request rcvaram#33 from AlankritaShah/patch-3
Browse files Browse the repository at this point in the history
created TOANDFRO
  • Loading branch information
rcvaram authored Oct 25, 2019
2 parents 9b8f3cd + fdd65a0 commit 5de62df
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions Java/TOANDFRO
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import java.util.Scanner;

class Main {
public static void main(String[] args)throws java.lang.Exception
{
Scanner sc=new Scanner(System.in);
int col=sc.nextInt();
while(col!=0)
{
String msg=sc.next();
int row=msg.length()/col;
char encmsg[][]=new char[row][col];
char newmsg[]=new char[msg.length()];
for(int i=0;i<row;i++)
{
for(int j=0;j<col;j++)
{
if(i%2==0)
{
encmsg[i][j]=msg.charAt(i*col+j);
}
else
{
encmsg[i][j]=msg.charAt(i*col+col-j-1);
}
}
//System.out.println();
}
int k=0;
for(int i=0;i<col;i++)
{
for(int j=0;j<row;j++)
{
newmsg[k]=encmsg[j][i];
k++;
}
}
for(k=0;k<msg.length();k++)
System.out.print(newmsg[k]);
System.out.println();

col=sc.nextInt();
}
sc.close();
}
}

0 comments on commit 5de62df

Please sign in to comment.