import java.io.*;
import java.util.*;
public class DataRecov
{
public static String[][] sort(String[][] bothnext)
{
String[][] bothfinal = bothnext;
int currentnum = 1;
for (int i = 0; i < bothfinal.length; i++)
{
if (currentnum == bothfinal.length) currentnum = 1;
for (int j = i; j < bothfinal.length; j++)
{
int a = Integer.parseInt(bothfinal[i][0]);
int b = Integer.parseInt(bothfinal[j][0]);
if (b == currentnum || b == bothfinal.length+20)
{
//placeholder
String placenum = bothfinal[i][0];
String placeword = bothfinal[i][1];
bothfinal[i][0] = bothfinal[j][0];
bothfinal[i][1] = bothfinal[j][1];
bothfinal[j][0] = placenum;
bothfinal[j][1] = placeword;
break;
}
}
currentnum += 1;
}
return bothfinal;
}
public static void bin(BufferedReader in)
{
String line;
try
{
while ((line = in.readLine()) != null)
{
String[] bothlst = line.split(";");
String[] sentence = bothlst[0].split(" ");
String[] nums = bothlst[1].split(" ");
String[][] bothnext = new String[sentence.length][2];
for (int i = 0; i < bothnext.length; i++)
{
try
{
bothnext[i][0] = nums[i];
}
catch (Exception e)
{
//Note need to handle how to declare missing numbers in hint
bothnext[i][0] = Integer.toString(sentence.length+20);
}
bothnext[i][1] = sentence[i];
}
String[][] bothfinal = sort(bothnext);
for (int i = 0; i < bothfinal.length; i++)
{
if (i == bothfinal.length-1) System.out.println(bothfinal[i][1]);
else System.out.print(bothfinal[i][1]+ " ");
}
}
}
catch (Exception e)
{
System.out.println(e);
}
}
public static void main(String[] args)
{
try
{
FileReader inc = new FileReader(args[0]);
BufferedReader in = new BufferedReader(inc);
bin(in);
}
catch (Exception e)
{
System.out.println("File not found");
}
}
}
Comments