Skip to content

Instantly share code, notes, and snippets.

@hinckel
Last active September 6, 2016 02:37
Show Gist options
  • Save hinckel/0ecf70729dd823819d78391bb8089818 to your computer and use it in GitHub Desktop.
Save hinckel/0ecf70729dd823819d78391bb8089818 to your computer and use it in GitHub Desktop.
package exercicioaero;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
/**
* http://br.spoj.com/problems/AERO/
*
* @author Luiz Felipe Hinckel
*/
public class ExercicioAero {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
//BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
//BufferedReader br = new BufferedReader(new FileReader(new File("C:\\Users\\Luiz Felipe Hinckel\\aero.in"))
try (BufferedReader br = new BufferedReader(new FileReader(new File("C:\\Users\\Luiz Felipe Hinckel\\aero.in")))) {
int a = -1; //numero de aeroportos
int v = -1; //numero de voos
int origem = 0;
int destino = 0;
int qtMaiorTrafico = 0;
int aeroportoMaiorTrafico = 0;
int traffic[] = new int[100];
while (br.ready()) {
String line = br.readLine();
if (line.equals("0 0")) {
break;
}
String[] split = line.split(" ");
if (a < 0) {
a = Integer.parseInt(split[0]);
v = Integer.parseInt(split[1]);
} else {
origem = Integer.parseInt(split[0]);
destino = Integer.parseInt(split[1]);
traffic[origem]++;
traffic[destino]++;
}
}
int temp;
for (int i = 1; i <= a; i++) {
temp = traffic[i];
if (temp >= qtMaiorTrafico) {
qtMaiorTrafico = temp;
aeroportoMaiorTrafico = i;
}
}
System.out.println("Teste 1");
System.out.println(aeroportoMaiorTrafico);
System.out.println("");
System.out.println("Teste 2");
int temp2;
for (int i = 1; i <= a; i++) {
temp2 = traffic[i];
if (temp2 == qtMaiorTrafico
&& i != aeroportoMaiorTrafico) {
System.out.print(i + " ");
}
}
System.out.println("");
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment