Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Competicao {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- int nAtletas = sc.nextInt();
- Atletas[] atletas = new Atletas[nAtletas];
- for (int i = 0; i < nAtletas; i++) {
- atletas[i] = new Atletas(sc.next(), new int[] { sc.nextInt(), sc.nextInt(), sc.nextInt(), sc.nextInt(), sc.nextInt() });
- atletas[i].calcSoma();
- }
- Atletas sorted;
- for (int i = 0; i < atletas.length; i++) {
- for (int j = 0; j < atletas.length-1; j++) {
- if (atletas[j+1].getSoma() < atletas[j].getSoma()) {
- sorted = atletas[j+1];
- atletas[j+1] = atletas[j];
- atletas[j] = sorted;
- }
- }
- }
- for (int i = 0; i < atletas.length; i++) {
- System.out.print(atletas[i].getNome() + " ");
- System.out.println(atletas[i].getSoma());
- }
- }
- }
- class Atletas {
- private String nome;
- private int[] tempos;
- private int soma;
- public Atletas(String nome, int tempos[]) {
- this.nome = nome;
- for (int tem : tempos)
- this.tempos = tempos;
- }
- public String getNome() {
- return this.nome;
- }
- public int getSoma() {
- return soma;
- }
- public void calcSoma() {
- for (int i = 0; i < tempos.length; i++)
- soma += tempos[i];
- }
- public int getTempo(int linha) {
- return this.tempos[linha];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement