试题编号: | 201909-1 |
试题名称: | 小明种苹果 |
时间限制: | 2.0s |
内存限制: | 512.0MB |
问题描述: | |
1 #include <bits/stdc .h> 2 3 using namespace std; 4 5 const int C=1001; 6 7 struct data 8 { 9 int ID; 10 int isum; 11 int leftNum; 12 }dat[C]; 13 14 bool cmp(struct data a,struct data b) 15 { 16 if(a.isum==b.isum) 17 return a.ID<b.ID; 18 return a.isum>b.isum; 19 } 20 int main() 21 { 22 int N,M; 23 cin>>N>>M; 24 int t; 25 int T = 0; 26 for(int i=0;i<N;i )///初始化 27 { 28 dat[i].ID = i 1; 29 dat[i].isum = 0; 30 } 31 for(int i=0;i<N;i ) 32 { 33 for(int j=0;j<=M;j ) 34 { 35 cin>>t; 36 if(j==0) 37 { 38 dat[i].leftNum = t; 39 //cout<<"leftNum is:"<<dat[i].leftNum<<" "; 40 } 41 else 42 { 43 dat[i].leftNum = t;///剩余果数 44 dat[i].isum = abs(t);///疏果个数 45 //cout<<"leftNum is:"<<dat[i].leftNum<<" "; 46 //cout<<"isum is:"<<dat[i].isum<<" "; 47 } 48 } 49 //cout<<endl; 50 } 51 for(int i = 0;i < N; i ) 52 { 53 T = dat[i].leftNum; 54 } 55 sort(dat,dat N,cmp); 56 cout<<T<<" "<<dat[0].ID<<" "<<dat[0].isum<<endl; 57 return 0; 58 } 59 /* 60 3 3 61 73 -8 -6 -4 62 76 -5 -10 -8 63 80 -6 -15 0 64 */
sort()是不稳定排序,用的时候条件要写全
今天考csp,加油