A 1141 PAT Ranking of Institutions(25점)

1924 단어

1. 기술 총결산



  • 2. 참고 코드

    #include
    #include
    #include
    #include
    #include
    using namespace std;
    struct node_i{
    	string name;
    	double all_score;
    	int num;
    };
    bool cmp(node_i a, node_i b){
    	if(a.all_score != b.all_score) return a.all_score > b.all_score;
    	else if(a.num != b.num) return a.num < b.num;
    	else return a.name < b.name;
    }
    int main(){
    	int n, index = 0;
    	vector v;
    	map f;
    	set e_sch;
    	scanf("%d", &n);
    	for(int i = 0; i < n; i++){
    		string s, sch;
    		double sc;
    		cin >> s >> sc >> sch;
    		transform(sch.begin(), sch.end(), sch.begin(), ::tolower);
    		if(e_sch.find(sch) != e_sch.end()){
    			if(s[0] == 'B') v[f[sch]].all_score += sc/1.5;
    			else if(s[0] == 'A') v[f[sch]].all_score += sc;
    			else v[f[sch]].all_score += sc*1.5;
    			v[f[sch]].num++;
    		}else{
    			double temp_sc;
    			if(s[0] == 'B') temp_sc = sc/1.5;
    			else if(s[0] == 'A') temp_sc = sc;
    			else temp_sc = sc*1.5;
    			v.push_back(node_i{sch, temp_sc, 1});
    			e_sch.insert(sch);
    			f[sch] = index++;
    		}
    	}
    	for(int i = 0; i < v.size(); i++){
    		v[i].all_score = int(v[i].all_score);
    	} 
    	sort(v.begin(), v.end(), cmp);
    	int rank;
    	cout << e_sch.size() << endl;
    	for(int i = 1; i <= v.size(); ++i){
    		if(i != 1 && v[i-1].all_score == v[i-2].all_score){
    			cout << rank << " " << v[i-1].name << " " << int(v[i-1].all_score) << " " << v[i-1].num << endl;
    		}else{
    			cout << i << " " << v[i-1].name << " " << int(v[i-1].all_score) << " " << v[i-1].num << endl;
    			rank = i;
    		}
    	}
    	return 0;
    }
    

    좋은 웹페이지 즐겨찾기