#include<bits×dc++.h> using namespace std; class apple { private: int num; string id; int weight; int diameter; public: void set(int a,string b,int c,int d) { num=a; id=b; weight=c; diameter=d; } int getnum() { return num; } int getweight() { return weight; } void print() { cout<<num<<" “<<id<<” “<<weight<<” "<<diameter<<endl; } }; int main() { int n,k,max; cin>>n; int index[n]; apple app[n]; for(int i=0;i<n;i++) { int a;string b;int c;int d; cin>>a>>b>>c>>d; app[i].set(a,b,c,d); } for(int i=0;i<n-1;i++) { for(int j=0;j<n-i-1;j++) { if(app[j].getnum()>app[j+1].getnum()) { apple temp=app[j]; app[j]=app[j+1]; app[j+1]=temp; } } } for(int i=0;i<n;i++) { k=app[i].getnum(); max=app[i].getweight(); for(int j=0;j<n;j++) { if(app[j].getnum()==k&&app[j].getweight()>=max) { max=app[j].getweight(); index[i]=j; } } } for(int i=0;i<n;i++) if(index[i]==i) { app[index[i]].print(); } return 0; }
|