11 solutions

  • 1
    @ 2022-4-3 18:14:37

    啊这,如果是比赛的话,肯定就用 sort 函数了。写个 cmp 就随便打。

    #include <iostream>
    #include <algorithm>
    
    using namespace std;
    
    struct node2 {
    	string name;// 姓名
    	int score;// 乘积
    };
    
    bool cmp(node2 a, node2 b) {
    	return a.score > b.score;
    }
    
    
    int main(void) {
    	int N;
    	cin >> N;
    
    	node2* arr = new node2[N];
    
    	for (int i = 0; i < N; ++i) {
    		string name;
    		int score;
    		cin >> arr[i].name >> arr[i].score;
    	}
    
    	sort(arr,arr+N,cmp);
    	
    	for (int i = 0; i < N; ++i) {
    		string str = "";
    		int score = arr[i].score;
    		if (score == 0) {
    			str = "Bad";
    		}else if (score >= 1 && score < 200) {
    			str = "Not good";
    		}else if (score >= 200 && score < 300) {
    			str = "Bronze medal";
    		}else if (score >= 300 && score < 400) {
    			str = "Silver medal";
    		}else if (score >= 400) {
    			str = "Gold medal";
    		}
    
    		cout << arr[i].name << " " << arr[i].score << " " << str << endl;
    	}
    
    
    	return 0;
    }
    

    Information

    ID
    110
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    5
    Tags
    # Submissions
    215
    Accepted
    79
    Uploaded By