Advertisement
dfilipeloja

Ex 3 mooshak alternativa

Apr 13th, 2015
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.66 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Competicao {
  4.    
  5.     public static void main(String[] args) {
  6.         Scanner sc = new Scanner(System.in);
  7.         int nAtletas = sc.nextInt();
  8.        
  9.         Atletas[] atletas = new Atletas[nAtletas];
  10.         for (int i = 0; i < nAtletas; i++) {
  11.             atletas[i] = new Atletas(sc.next(), new int[] { sc.nextInt(), sc.nextInt(), sc.nextInt(), sc.nextInt(), sc.nextInt() });
  12.             atletas[i].calcSoma();
  13.         }
  14.        
  15.         Atletas sorted;
  16.        
  17.         for (int i = 0; i < atletas.length; i++) {
  18.             for (int j = 0; j < atletas.length-1; j++) {
  19.                 if (atletas[j+1].getSoma() < atletas[j].getSoma()) {
  20.                     sorted = atletas[j+1];
  21.                     atletas[j+1] = atletas[j];
  22.                     atletas[j] = sorted;
  23.                 }
  24.             }
  25.         }
  26.        
  27.         for (int i = 0; i < atletas.length; i++) {
  28.             System.out.print(atletas[i].getNome() + " ");
  29.             System.out.println(atletas[i].getSoma());
  30.         }
  31.     }  
  32. }
  33.  
  34. class Atletas {
  35.    
  36.     private String nome;
  37.     private int[] tempos;
  38.     private int soma;
  39.    
  40.     public Atletas(String nome, int tempos[]) {
  41.         this.nome = nome;
  42.        
  43.         for (int tem : tempos)
  44.             this.tempos = tempos;
  45.     }
  46.    
  47.     public String getNome() {
  48.         return this.nome;
  49.     }
  50.    
  51.     public int getSoma() {
  52.         return soma;
  53.     }
  54.    
  55.     public void calcSoma() {
  56.         for (int i = 0; i < tempos.length; i++)
  57.             soma += tempos[i];
  58.     }
  59.    
  60.     public int getTempo(int linha) {
  61.         return this.tempos[linha];
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement