c++还真的比java要效率,一下午两道题java都超时,c++竟然AC了
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
int NN, MM, i, j;
cin>>NN>>MM;
string idStrings[NN],idString;
int C[NN], M[NN], E[NN], A[NN], rank[4];
for(i = 0; i < NN; i++){
cin>>idStrings[i]>>C[i]>>M[i]>>E[i];
A[i] = (C[i]+M[i]+E[i])/3;
}
int index;
for(i = 0; i < MM; i++){
cin>>idString;
index = -1;
for(j = 0 ; j < NN; j++){
if(idString == idStrings[j]){
index = j;
break;
}
}
if(-1 == index){
cout<<"N/A"<<endl;
}
else{
for(j = 0; j < 4; j++){
rank[j] = 1;
}
for(j = 0; j < NN; j++){
if(j != index){
if(A[j] > A[index]){
rank[0]++;
}
if(C[j] > C[index]){
rank[1]++;
}
if(M[j] > M[index]){
rank[2]++;
}
if(E[j] > E[index]){
rank[3]++;
}
}
}
int r = rank[0];
int dex = 0;
for(j = 1; j < 4; j++){
if(rank[j] < r){
r = rank[j];
dex = j;
}
}
char ch;
switch (dex) {
case 0:
ch = 'A';
break;
case 1:
ch = 'C';
break;
case 2:
ch = 'M';
break;
case 3:
ch = 'E';
break;
}
cout<<r<<" "<<ch<<endl;
}
}
}