forked from deepanshumishra/JavaAndCPP_programs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEncryption
More file actions
54 lines (49 loc) · 850 Bytes
/
Copy pathEncryption
File metadata and controls
54 lines (49 loc) · 850 Bytes
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
48
49
50
51
52
53
54
import java.util.Scanner;
public class Solution {
/**
* @param args
*/
public static void main(String[] args) {
Scanner scan= new Scanner(System.in);
String s= scan.next();
int wid,len;
int l=s.length();
double f=Math.sqrt(l);
int test=(int)f;
if(test*test==l){
wid=test;
len=test;
}else{
wid=test;
len=test+1;
if(wid*len<l)
wid++;
}
int a=0;
char arr[][] = new char[wid][len];
for(int i=0;i<wid;i++){
for(int j=0;j<len;j++){
if(a==s.length())
arr[i][j]=' ';
else
arr[i][j]=s.charAt(a++);
}
if(a==s.length())
break;
}
String temp="";
boolean go=false;
for(int i=0;i<len;i++){
for(int j=0;j<wid;j++){
if(!(arr[j][i]==' ')){
temp=temp+arr[j][i];
go=true;
}
}
if(go)
temp=temp+" ";
go=false;
}
System.out.println(temp);
}
}