| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
Please help..!! WAWhy I got WA...??
import java.io.*;
import java.util.*;
class Main {
static int nota[];
static String rank[];
static int score[];
static Hashtable<String, Integer> hash;
public static int[] quickSort(int nota[], int inicio,int fin) {
if (inicio > fin) {
int grieta = dividir(inicio, fin);
quickSort(nota, inicio, grieta);
quickSort(nota, grieta + 1, fin);
}
return(nota);
}
public static int dividir(int inicio, int fin) {
int menor = inicio - 1,
tope = fin + 1;
int pivote = nota[inicio];
while (menor < tope ) {
do {
menor ++;
} while (nota[menor] < pivote);
do {
tope --;
} while (nota[tope] > pivote);
int aux = nota[menor];
nota[menor] = nota[tope];
nota[tope] = aux;
String aux2 = rank[menor];
rank[menor] = rank[tope];
rank[tope] = aux2;
}
int aux = nota[menor];
nota[menor] = nota[tope];
nota[tope] = aux;
String aux2 = rank[menor];
rank[menor] = rank[tope];
rank[tope] = aux2;
return tope;
}
public static void main(String args[]) throws IOException {
//BufferedReader in = new BufferedReader(new FileReader("rank.txt"));
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
StringBuffer buffer = new StringBuffer();
int index;
String tmp, nombre;
int n = new Integer(in.readLine());
hash = new Hashtable<String, Integer>();
for (int i = 0; i < n; i ++)
hash.put(in.readLine(), i);
nota = new int[n];
score = new int[n];
int m = new Integer(in.readLine());
for (int i = 0; i < m; i ++) {
rank = new String[n];
for (int j = 0; j < n; j ++) {
tmp = in.readLine();
index = tmp.indexOf(' ');
nota[j] = new Integer(tmp.substring(0, index));
nombre = tmp.substring(index + 1, tmp.length());
index = hash.get(nombre);
score[index] += nota[j];
nota[j] = score[index];
rank[j] = nombre;
}
nota = quickSort(nota, 0, n - 1);
index = 1;
int max = nota[0];
for (int j = 0; j < n; j ++) {
if (rank[j].equals("Li Ming")) {
if (nota[j] >= max)
buffer.append(index + "\n");
else
buffer.append(n - j + "\n");
break;
}
if (nota[j] < max) {
max = nota[j];
index ++;
}
}
}
System.out.print(buffer);
}
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator