11 solutions
-
0
利用结构体sort排序,在用条件语句判断
#include<stdio.h> #include<algorithm> #include<string> #include<vector> #include<iostream> using namespace std; int n; struct cj { string name; int grade; }s[1000]; int cmp(cj a,cj b) { return a.grade>b.grade; } int main() { scanf("%d",&n); for(int i=0;i<n;i++) { cin>>s[i].name>>s[i].grade; } sort(s,s+n,cmp); for(int i=0;i<n;i++) { if(s[i].grade>=1&&s[i].grade<200) { cout<<s[i].name<<" "<<s[i].grade<<" "<<"Not good"<<endl; }else if(s[i].grade>=200&&s[i].grade<300) { cout<<s[i].name<<" "<<s[i].grade<<" "<<"Bronze medal"<<endl; }else if(s[i].grade>=300&&s[i].grade<400) { cout<<s[i].name<<" "<<s[i].grade<<" "<<"Silver medal"<<endl; }else if(s[i].grade>=400) { cout<<s[i].name<<" "<<s[i].grade<<" "<<"Gold medal"<<endl; }else cout<<s[i].name<<" "<<s[i].grade<<" "<<"Bad"<<endl; } return 0; }
Information
- ID
- 110
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 5
- Tags
- # Submissions
- 211
- Accepted
- 77
- Uploaded By