|
| 1 | +import java.util.Scanner; |
| 2 | + |
| 3 | +public class App { |
| 4 | + static Scanner s = new Scanner(System.in); |
| 5 | + |
| 6 | + public static void main(String[] args) throws Exception { |
| 7 | + MyIO.setCharset("UTF-8"); |
| 8 | + |
| 9 | + // lê os dados dos jogadores |
| 10 | + Jogador[] jogadores = lerJogadores(); |
| 11 | + |
| 12 | + String numLinhas = s.nextLine(); |
| 13 | + |
| 14 | + // s.nextLine(); |
| 15 | + |
| 16 | + // Array com ids |
| 17 | + String[] ids = new String[Integer.parseInt(numLinhas)]; |
| 18 | + |
| 19 | + for (int i = 0; i < ids.length; i++) { |
| 20 | + try { |
| 21 | + ids[i] = s.nextLine(); |
| 22 | + } catch (Exception e) { |
| 23 | + } |
| 24 | + } |
| 25 | + |
| 26 | + s.close(); |
| 27 | + |
| 28 | + for (String i : ids) { |
| 29 | + if (i != null && !i.isEmpty()) { |
| 30 | + for (Jogador jogador : jogadores) { |
| 31 | + if (jogador.getId() == Integer.parseInt(i)) { |
| 32 | + jogador.imprimir(); |
| 33 | + } |
| 34 | + } |
| 35 | + } |
| 36 | + } |
| 37 | + |
| 38 | + } |
| 39 | + |
| 40 | + public static class Jogador { |
| 41 | + private int id; |
| 42 | + private String nome; |
| 43 | + private int altura; |
| 44 | + private int peso; |
| 45 | + private String universidade; |
| 46 | + private int anoNascimento; |
| 47 | + private String cidadeNascimento; |
| 48 | + private String estadoNascimento; |
| 49 | + |
| 50 | + // Construtores da classe |
| 51 | + public Jogador() { |
| 52 | + } |
| 53 | + |
| 54 | + public Jogador(int id, String nm, int altura, int peso, String unv, int aNas, |
| 55 | + String cNas, String eNas) { |
| 56 | + this.id = id; |
| 57 | + this.nome = nm; |
| 58 | + this.altura = altura; |
| 59 | + this.peso = peso; |
| 60 | + this.universidade = unv; |
| 61 | + this.anoNascimento = aNas; |
| 62 | + this.cidadeNascimento = cNas; |
| 63 | + this.estadoNascimento = eNas; |
| 64 | + } |
| 65 | + |
| 66 | + Jogador(String packet) { |
| 67 | + String[] tokens = packet.split(",", -1); |
| 68 | + // - id do jogador; |
| 69 | + // - nome do jogador; |
| 70 | + // - sua altura; |
| 71 | + // - seu peso; |
| 72 | + // - universidade que o jogador representa; |
| 73 | + // - ano de nascimento do jogador; |
| 74 | + // - nome da cidade em que o jogador nasceu; |
| 75 | + // - estado em que o jogador nasceu. |
| 76 | + |
| 77 | + try { |
| 78 | + this.id = Integer.parseInt(tokens[0]); |
| 79 | + } catch (Exception e) { |
| 80 | + // handle exception |
| 81 | + } |
| 82 | + |
| 83 | + try { |
| 84 | + this.nome = tokens[1]; |
| 85 | + } catch (Exception e) { |
| 86 | + // handle exception |
| 87 | + } |
| 88 | + |
| 89 | + try { |
| 90 | + this.altura = Integer.parseInt(tokens[2]); |
| 91 | + } catch (Exception e) { |
| 92 | + // handle exception |
| 93 | + } |
| 94 | + |
| 95 | + try { |
| 96 | + this.peso = Integer.parseInt(tokens[3]); |
| 97 | + } catch (Exception e) { |
| 98 | + // handle exception |
| 99 | + } |
| 100 | + |
| 101 | + try { |
| 102 | + this.universidade = tokens[4]; |
| 103 | + } catch (Exception e) { |
| 104 | + // handle exception |
| 105 | + } |
| 106 | + |
| 107 | + try { |
| 108 | + this.anoNascimento = Integer.parseInt(tokens[5]); |
| 109 | + } catch (Exception e) { |
| 110 | + // handle exception |
| 111 | + } |
| 112 | + |
| 113 | + try { |
| 114 | + this.cidadeNascimento = tokens[6]; |
| 115 | + } catch (Exception e) { |
| 116 | + // handle exception |
| 117 | + } |
| 118 | + |
| 119 | + try { |
| 120 | + this.estadoNascimento = tokens[7]; |
| 121 | + } catch (Exception e) { |
| 122 | + // handle exception |
| 123 | + } |
| 124 | + } |
| 125 | + |
| 126 | + // getters |
| 127 | + public int getId() { |
| 128 | + return id; |
| 129 | + } |
| 130 | + |
| 131 | + public String getNome() { |
| 132 | + return nome; |
| 133 | + } |
| 134 | + |
| 135 | + public int getAltura() { |
| 136 | + return altura; |
| 137 | + } |
| 138 | + |
| 139 | + public int getPeso() { |
| 140 | + return peso; |
| 141 | + } |
| 142 | + |
| 143 | + public String getUniversidade() { |
| 144 | + return universidade; |
| 145 | + } |
| 146 | + |
| 147 | + public int getAnoNascimento() { |
| 148 | + return anoNascimento; |
| 149 | + } |
| 150 | + |
| 151 | + public String getCidadeNascimento() { |
| 152 | + return cidadeNascimento; |
| 153 | + } |
| 154 | + |
| 155 | + public String getEstadoNascimento() { |
| 156 | + return estadoNascimento; |
| 157 | + } |
| 158 | + |
| 159 | + // setters |
| 160 | + public void setId(int id) { |
| 161 | + this.id = id; |
| 162 | + } |
| 163 | + |
| 164 | + public void setNome(String nome) { |
| 165 | + this.nome = nome; |
| 166 | + } |
| 167 | + |
| 168 | + public void setAltura(int altura) { |
| 169 | + this.altura = altura; |
| 170 | + } |
| 171 | + |
| 172 | + public void setPeso(int peso) { |
| 173 | + this.peso = peso; |
| 174 | + } |
| 175 | + |
| 176 | + public void setUniversidade(String universidade) { |
| 177 | + this.universidade = universidade; |
| 178 | + } |
| 179 | + |
| 180 | + public void setAnoNascimento(int anoNascimento) { |
| 181 | + this.anoNascimento = anoNascimento; |
| 182 | + } |
| 183 | + |
| 184 | + public void setCidadeNascimento(String cidadeNascimento) { |
| 185 | + this.cidadeNascimento = cidadeNascimento; |
| 186 | + } |
| 187 | + |
| 188 | + public void setEstadoNascimento(String estadoNascimento) { |
| 189 | + this.estadoNascimento = estadoNascimento; |
| 190 | + } |
| 191 | + |
| 192 | + // Outros métodos |
| 193 | + public void imprimir() { |
| 194 | + System.out.print("[" + this.id); |
| 195 | + |
| 196 | + if (this.nome != null && !this.nome.isEmpty()) { |
| 197 | + System.out.print(" ## " + this.nome); |
| 198 | + } else { |
| 199 | + System.out.print(" ## nao informado"); |
| 200 | + } |
| 201 | + |
| 202 | + if (this.altura != 0.0) { |
| 203 | + System.out.print(" ## " + this.altura); |
| 204 | + } else { |
| 205 | + System.out.print("## nao informado"); |
| 206 | + } |
| 207 | + |
| 208 | + if (this.peso != 0.0) { |
| 209 | + System.out.print(" ## " + this.peso); |
| 210 | + } else { |
| 211 | + System.out.print("## nao informado"); |
| 212 | + } |
| 213 | + |
| 214 | + if (this.anoNascimento != 0) { |
| 215 | + System.out.print(" ## " + this.anoNascimento); |
| 216 | + } else { |
| 217 | + System.out.print(" ## nao informado"); |
| 218 | + } |
| 219 | + |
| 220 | + if (this.universidade != null && !this.universidade.isEmpty()) { |
| 221 | + System.out.print(" ## " + this.universidade); |
| 222 | + } else { |
| 223 | + System.out.print(" ## nao informado"); |
| 224 | + } |
| 225 | + |
| 226 | + if (this.cidadeNascimento != null && !this.cidadeNascimento.isEmpty()) { |
| 227 | + System.out.print(" ## " + this.cidadeNascimento); |
| 228 | + } else { |
| 229 | + System.out.print(" ## nao informado"); |
| 230 | + } |
| 231 | + |
| 232 | + if (this.estadoNascimento != null && !this.estadoNascimento.isEmpty()) { |
| 233 | + System.out.print(" ## " + this.estadoNascimento); |
| 234 | + } else { |
| 235 | + System.out.print(" ## nao informado"); |
| 236 | + } |
| 237 | + |
| 238 | + System.out.println("]"); |
| 239 | + |
| 240 | + } |
| 241 | + } |
| 242 | + |
| 243 | + private static Jogador[] lerJogadores() { |
| 244 | + // Scanner s = new Scanner(System.in); |
| 245 | + |
| 246 | + // lê os dados dos jogadores e adiciona ao vetor de jogadores |
| 247 | + Jogador[] jogadores = new Jogador[20000]; |
| 248 | + int numJogadores = 0; |
| 249 | + String linha = s.nextLine(); |
| 250 | + |
| 251 | + while (!linha.equals("FIM")) { |
| 252 | + Jogador jogador = new Jogador(linha); |
| 253 | + |
| 254 | + jogadores[numJogadores] = jogador; |
| 255 | + numJogadores++; |
| 256 | + |
| 257 | + linha = s.nextLine(); |
| 258 | + } |
| 259 | + |
| 260 | + // s.nextLine(); |
| 261 | + // s.close(); |
| 262 | + |
| 263 | + // cria um novo vetor de jogadores com o tamanho exato do número de jogadores |
| 264 | + // lidos |
| 265 | + Jogador[] jogadoresFinais = new Jogador[numJogadores]; |
| 266 | + for (int i = 0; i < numJogadores; i++) { |
| 267 | + jogadoresFinais[i] = jogadores[i]; |
| 268 | + } |
| 269 | + |
| 270 | + // for (Jogador jogador : jogadoresFinais) { |
| 271 | + // jogador.imprimir(); |
| 272 | + // } |
| 273 | + |
| 274 | + return jogadoresFinais; |
| 275 | + } |
| 276 | +} |
0 commit comments