-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCipher.java
More file actions
33 lines (33 loc) · 793 Bytes
/
Cipher.java
File metadata and controls
33 lines (33 loc) · 793 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
import java.io.*;
import java.util.*;
public class Cipher{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int textLength = sc.nextInt();
//Scanner sc1 = new Scanner(System.in);
String encryptedText = sc.next();
char[] encryptedChar = encryptedText.toCharArray();
int originalLen=0;
if(textLength ==1){
originalLen = textLength;
}else{
int temp = textLength*2;
//find n
int i=2;
while(i< temp/2){
if((i*(i+1))==temp){
originalLen = i;
break;
}else{
i++;
}
}
}
char[] originalText = new char[originalLen];
for(int i=0, j=0; i < encryptedChar.length && j < originalLen ; j++){
originalText[j] = encryptedChar[i];
i = ((j+1)*(j+2))/2;
}
System.out.println(new String(originalText));
}
}