-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEncryption-Java
47 lines (35 loc) · 1009 Bytes
/
Encryption-Java
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
import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.regex.*;
import java.lang.Math;
class Result {
public static String encryption(String s) {
String st = s.replaceAll("\\s", "");
int l=s.length();
double r=Math.floor(Math.sqrt(l));
double c=Math.ceil(Math.sqrt(l));
int len=(int) (r>c?r:c);
String result = "";
for(int i=0;i<len;i++) {
for(int j=i;j<l;j += (int)c) {
char ch=s.charAt(j);
result+=ch;
}
result+=" ";
}
return result;
}
}
public class Solution {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
String str = new String();
str = sc.nextLine();
String result = Result.encryption(str);
System.out.print(result);
}
}