Example #1
0
  public static void main(String[] args) throws IOException {
    IO io = new IO(System.in);
    int sum;

    while (true) {

      int nV = io.nextInt();
      int nE = io.nextInt();
      if (nV == 0) {
        break;
      }
      V[] vertices = new V[nV];
      E[] edges = new E[nE];

      for (int j = 0; j < nV; j++) {
        vertices[j] = new V(j);
      }

      for (int j = 0; j < nE; j++) {
        int start = io.nextInt();
        int end = io.nextInt();
        double w = io.nextDouble();
        if (end > start) {
          edges[j] = new E(vertices[start], vertices[end], w);
        } else {
          edges[j] = new E(vertices[end], vertices[start], w);
        }
      }

      ArrayList<E> result = compute(nV, edges);
      if (result.size() > 0) {
        sum = 0;
        for (int i = 0; i < result.size(); i++) {
          sum += result.get(i).w;
        }
        io.println(sum);
        String[] resultStrings = new String[result.size()];
        for (int i = 0; i < result.size(); i++) {
          resultStrings[i] = "" + result.get(i).start.name + " " + result.get(i).end.name;
        }
        Arrays.sort(resultStrings);
        for (int i = 0; i < result.size(); i++) {
          io.printf("%s\n", resultStrings[i]);
        }
      } else {
        io.println("Impossible");
      }
    }

    io.close();
  }
Example #2
0
 protected void assertEqual(final Object expected, final Object actual) {
   if (!(Utils.equals(expected, actual))) {
     IO.print("Valor atingido (");
     IO.print(((Object) actual));
     IO.print(") diferente do esperado (");
     IO.print(((Object) expected));
     IO.println(")");
   } else {
     IO.print("Valor atingido (");
     IO.print(((Object) actual));
     IO.print(") corresponde ao esperado (");
     IO.print(((Object) expected));
     IO.println(")");
   }
 }
Example #3
0
 public void execute() throws InvalidOperation {
   List<Employee> employees = _entity.getListOfEmployees();
   Collections.sort(employees, new SortEmployeesByKey());
   for (Employee e : employees) {
     IO.println(e.toString());
   }
 }
  public static void main(String[] args) {
    // definir objeto
    L02E01 EX01 = new L02E01();
    L02E02 EX02 = new L02E02();
    L02E03 EX03 = new L02E03();
    L02E04 EX04 = new L02E04();
    L02E05 EX05 = new L02E05();
    L02E06 EX06 = new L02E06();
    L02E07 EX07 = new L02E07();

    // declarar variáveis
    int opcao;

    // identificar programa
    IO.windowON();
    IO.println("Lista 02\nLeonel Fonseca Ivo");
    IO.windowOFF();

    // definir valor
    IO.windowON();
    opcao =
        IO.readint(
            "Escolha o exercício a ser mostrado:\n1 - Exercício 1\n2 - Exercício 2\n3 - Exercício 3\n4 - Exercício 4\n5 - Exercício 5\n6 - Exercício 6\n7 - Exercício 7\n");
    IO.windowOFF();
    switch (opcao) {
      case 1:
        EX01.Exec1();
        break;
      case 2:
        EX02.Exec2();
        break;
      case 3:
        EX03.Exec3();
        break;
      case 4:
        EX04.Exec4();
        break;
      case 5:
        EX05.Exec5();
        break;
      case 6:
        EX06.Exec6();
        break;
      case 7:
        EX07.Exec7();
        break;
    }
  }
Example #5
0
 /** Changes the Tree's habitat */
 public void execute() throws InvalidOperation {
   String key;
   Tree t;
   Decidous d;
   try {
     key = IO.readString(treeKeyReq());
     t = _entity.getTree(key);
     if (t.getType().compareTo(caduca()) == 0) {
       d = (Decidous) t;
       while (((key = IO.readString(treeNewBiological())).compareTo(withLeaves()) != 0)
           && (key.compareTo(withoutLeaves()) != 0)
           && (key.compareTo(fallingLeaves()) != 0)
           && (key.compareTo(growingLeaves()) != 0)) ;
       d.setBiologicalCycle(key);
       _entity.setChanged(true);
     }
     return;
   } catch (IOException e) {
     IO.println(e.toString());
     return;
   }
 }