2 solutions
-
1
#include<bits/stdc++.h> using namespace std; int n; int chn[305]; int sum[305]; int id[305]; bool cmp(int x,int y){ if(sum[x]!=sum[y]) return(sum[x]>sum[y]); if(chn[x]!=chn[y]) return(chn[x]>chn[y]); return(id[x]<id[y]); } void SWAP(int x,int y){ swap(sum[x],sum[y]); swap(chn[x],chn[y]); swap(id[x],id[y]); } int main(){ cin>>n; for(int i=1;i<=n;i++){ int x,y,z; cin>>x>>y>>z; chn[i]=x; sum[i]=x+y+z; id[i]=i; } for(int i=1;i<=n;i++) for(int j=i;j<=n;j++) if(cmp(j,i)) SWAP(j,i); for(int i=1;i<=5;i++) cout<<id[i]<<" "<<sum[i]<<endl; return 0; }
-
0
#include #include #include 这是错误的题解
int main() { int n; std::cin >> n; std::vector students(n);
for (int i = 0; i < n; ++i) { students[i].id = i + 1; std::cin >> students[i].chinese >> students[i].math >> students[i].english; students[i].total = students[i].chinese + students[i].math + students[i].english; }
std::sort(students.begin(), students.end(), compare);
for (int i = 0; i < std::min(5, n); ++i) { std::cout << students[i].id << " " << students[i].total << std::endl; }
return 0;
}
- 1
Information
- ID
- 93
- Time
- 1000ms
- Memory
- 125MiB
- Difficulty
- 2
- Tags
- # Submissions
- 62
- Accepted
- 29
- Uploaded By