All pastes #229827 Raw Edit

p3

public java v1 · immutable
#229827 ·published 2006-10-30 23:24 UTC
rendered paste body
import java.io.*;class P3_BasketballStatistics2 {	static final String FIN = "DATA31.txt";	static final String FOUT = "OUT31.txt";		public static void main(String[] args)  {		try {						BufferedReader fin = new BufferedReader( new FileReader(FIN) );			PrintWriter fout = new PrintWriter(new FileWriter(FOUT));			main(fin, fout);			fin.close();			fout.close();		} catch ( IOException e ) {			System.err.println("Input file: " + FIN + " not found.");		}	}	public static void main(BufferedReader fin, PrintWriter fout) throws IOException {		int rep = Integer.parseInt( fin.readLine());		String[] names = new String[rep];		double[] ppm = new double[rep];		for (int i = 0; i < rep; i++) {			names[i] = fin.readLine();			int points = Integer.parseInt( fin.readLine() );			points += Integer.parseInt( fin.readLine() ) * 2;			points += Integer.parseInt( fin.readLine() ) * 3;			int minutes = Integer.parseInt( fin.readLine() );			ppm[i] = (double)points / minutes;		}		//get best 5;		for (int i = 0; i < 5 && i < rep; i++) {			int maxPos = i;			for (int j = i + 1; j < rep; j++) {				if ( ppm[j] > ppm[maxPos] ) {					maxPos = j;				}			}			double temp = ppm[maxPos];			ppm[maxPos] = ppm[i];			ppm[i] = temp;			String tem = names[maxPos];			names[maxPos] = names[i];			names[i] = tem;			fout.println(names[i] + "-" + format(ppm[i]) );		}		//print	}	static String format( double d) {		d = Math.round(d * 1000) / 1000.0;		//round d to 2 decimal digit		String str = ""+d;						//string representation of d				while ( str.length() - 1 - str.lastIndexOf('.') < 3 ) {			str += "0";		}				return str;	}}