All pastes #745080 Raw Edit

Miscellany

public text v1 · immutable
·published 2007-10-22 01:06 UTC
rendered paste body
import java.util.Scanner;
import java.util.ArrayList;

class Main{
	
	static StringBuilder sBuilder=new StringBuilder();
	
	public static void main (String[] args) {
		Scanner in=new Scanner(System.in);
		String s;
		
		String[] contestantData= new String [4];
		int numCases=Integer.parseInt(in.nextLine()); 
		in.nextLine();
		for (int i=0;i<numCases;i++){
			ArrayList<Contestant> contestants=new ArrayList<Contestant> ();
			do{
				s=in.nextLine();
				if(s.length()==0)
					break;
				contestantData=tokenize(s);
				getContestant(contestants,contestantData).eval(contestantData);			
			}
				while(s.length()!=0);
			for (int k=0; k<contestants.size();k++){
				takeOffPenaltyTimeforProblemsNotSolved(contestants.get(k));
			}
			
			sort(contestants);
			
			for(int j=0; j<contestants.size();j++){
				
				sBuilder.append(contestants.get(j));
				if(i!=numCases-1)
					sBuilder.append("\n");
				if(i==numCases-1){
					if(j!=contestants.size()-1)
						sBuilder.append("\n");
				}
			}
			if(i!=numCases-1)
				sBuilder.append("\n");
		}
		System.out.print(sBuilder);
	}
	public static void takeOffPenaltyTimeforProblemsNotSolved(Contestant alpha){
		for (int i=0; i<10; i++){
			if(alpha.problemsWrong[i]!=0){
				if(alpha.problemsCorrect[i]==0){
					alpha.time-=20;
				}
			}
		}
	}
	public static void sort (ArrayList <Contestant>beta){
		Contestant temp;
		Contestant temp2;
		int j;
		for (int i=1;i<beta.size();i++){
			temp=beta.get(i);
			j=i-1;
			while(j>-1&&beta.get(j).compareTo(temp)==1){
				temp2=beta.get(j+1);
				beta.set(j+1, beta.get(j));
				beta.set(j, temp2);
				j--;
			}
			beta.set(j+1,temp);
		}
	}
	 public static String[] tokenize(String s){
		 String [] tokens=new String [4];
		 tokens= s.split("\\s");
		 return tokens;
	 }
	 public static Contestant getContestant(ArrayList<Contestant>contestants,String[]alpha){
		 for (int i=0; i<contestants.size();i++){
			 if (contestants.get(i).ID==Integer.parseInt(alpha[0]))
				 return contestants.get(i);		
		 }
		 contestants.add(new Contestant(alpha));
		 return contestants.get(contestants.size()-1);
	 }
}

class Contestant implements Comparable{
	int ID;
	int probNum;
	int time;
	boolean isCorrect=false; 
	int numCorrect=0;
	int [] problemsWrong= new int[10];
	int[] problemsCorrect=new int[10];
	
	public Contestant(String alpha[]){
		ID=Integer.parseInt(alpha[0]);
		probNum=Integer.parseInt(alpha[1]);
	}
	
	public void eval(String alpha[]){
		if(alpha[3].equals("C")){
				if (problemsCorrect[Integer.parseInt(alpha[1])]==0){
					numCorrect++;
					time+=Integer.parseInt(alpha[2]);
					problemsCorrect[Integer.parseInt(alpha[1])]++;
				}	
			}	
		if(alpha[3].equals("I")){	
			problemsWrong[Integer.parseInt(alpha[1])]++;
			time+=20;
		}
	}	
	
	public String toString(){
		return ID+ " "+ numCorrect+" "+time ;
	}
	
	public int compareTo(Object b){
		Contestant a= (Contestant)b;
		if(this.numCorrect!=a.numCorrect){
			if (this.numCorrect< a.numCorrect){
				
				return 1;
			}
			return -1;
		}
		else if(this.numCorrect==a.numCorrect&&this.time!=a.time){
			if (this.time> a.time){
				return 1;
			}
			if (this.time== a.time)
				return 0;
			return -1;
		}
		else {
			if(this.ID!=a.ID){
				if(this.ID>a.ID)
					return 1;
				return -1;
			}
		}
		return 1;
	}
	
}