灵异现场(memset错在哪里??)
#include <iostream> #include <string> #include <string.h> #include <algorithm> using namespace std; const int MAXN=105; struct milk{ string brand; int V; float DP; milk(){} milk(string a,int b,float c):brand(a),V(b),DP(c){} }have[MAXN]; bool cmp(milk a,milk b){ return a.DP==b.DP?a.V>b.V:a.DP>b.DP; } int main(){ int T,N; cin>>T; while(T--){ //memset(have,0,sizeof(have)); 用memset会出BUG! cin>>N; int P,day; for(int i=0;i<N;i++){ cin>>have[i].brand>>P>>have[i].V; if(have[i].V>1000)day=5; else day=have[i].V/200; if(day==0)have[i]=milk{}; else have[i].DP=1.0*day/P; } sort(have,have+N,cmp); cout<<have[0].brand<<endl; } return 0; }
#include <iostream> #include <string> #include <string.h> #include <algorithm> using namespace std; const int MAXN=105; struct milk{ string brand; int V; float DP; milk(){} milk(string a,int b,float c):brand(a),V(b),DP(c){} }have[MAXN]; bool cmp(milk a,milk b){ return a.DP==b.DP?a.V>b.V:a.DP>b.DP; } int main(){ int T,N; cin>>T; while(T--){ //memset(have,0,sizeof(have)); 用memset会出BUG! cin>>N; int P,day; for(int i=0;i<N;i++){ cin>>have[i].brand>>P>>have[i].V; if(have[i].V>1000)day=5; else day=have[i].V/200; if(day==0)have[i]=milk{}; else have[i].DP=1.0*day/P; } sort(have,have+N,cmp); cout<<have[0].brand<<endl; } return 0; }
边完善自己边认识自己