Created
February 9, 2017 09:19
-
-
Save Omnyyah/5e7491682b41a1b60af9ab1e730ee6fa to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.ArrayList; | |
import java.util.Arrays; | |
import java.util.Collections; | |
import java.util.Scanner; | |
import java.lang.Object.*; | |
import java.util.List; | |
/** | |
* | |
* @author Manoo | |
*/ | |
public class Main { | |
static final char[] arr = "ABCDEFGHIJKLMNOPQRSTUVWXYZ ".toCharArray(); | |
static Integer[] row=new Integer[27]; | |
static Integer[] columns=new Integer[27]; | |
public static StringBuffer decode(Integer[] msg) | |
{ | |
StringBuffer gift=new StringBuffer(""); | |
for(int i=0;i<msg.length;i++) | |
{ | |
int index=msg[i]; | |
index=index-1; | |
int num=row[index]; | |
int letter=columns[num]; | |
columns=swap(columns,index); | |
row=swap(row,index); | |
gift.append(arr[letter]); | |
} | |
return gift; | |
} | |
public static Integer[] swap(Integer[] array,int index) | |
{ | |
if(index==26) | |
{ | |
return array; | |
} | |
int num=array[index]; | |
List<Integer> list=new ArrayList<Integer>(Arrays.asList(array)); | |
list.remove(num); | |
list.add(25, num); | |
array = list.toArray(array); | |
return array; | |
} | |
public static void main(String[] args) { | |
Scanner in=new Scanner(System.in); | |
int counter=0; | |
for(int i=0;i<row.length;i++) | |
{ | |
row[i]=i; | |
} | |
for(int j=0;j<columns.length;j++) | |
{ | |
columns[j]=j; | |
} | |
//System.out.println(row[0]); | |
//System.out.println(java.util.Arrays.toString(arr)); | |
//int T = in.nextInt(); | |
while(in.hasNextLine()) | |
{ | |
counter++; | |
int t=in.nextInt(); | |
in.nextLine(); | |
for(int j=0;j<t;j++) | |
{ | |
String userinput=in.nextLine(); | |
String[] arrrr=userinput.split(" "); | |
Integer[] userArray = new Integer[arrrr.length]; | |
for(int i = 0;i < arrrr.length;i++) | |
{ | |
int number=Integer.parseInt(arrrr[i]); | |
Integer num1=new Integer(number); | |
userArray[i] = num1; | |
} | |
// for(int i = 0;i < userArray.length;i++) | |
// { | |
// System.out.println(userArray[i]); | |
// } | |
StringBuffer Message = decode(userArray); | |
System.out.println(" LISTA #" + counter); | |
System.out.println(Message.toString()); | |
} | |
} | |
} | |
// | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment