分析
将每只股票存入结构体数组d中,然后枚举每个价格低于它的卖出数量和高于它的买入数量,每次二者取最小值,同时更新最大的开盘价。
C++ 代码
#include<bits/stdc++.h>using namespace std;const int N = 5e3+10;int idx;long long ansn=-1;struct node{int type;double price;int num;bool is_del=false;}d[N];double ansp=-1;int main(){string type;while (cin >> type){if(type=="buy"){double p;int s;cin >> p >> s;d[++idx]={1, p, s};}else if(type=="sell"){double p;int s;cin >> p >> s;d[++idx]={2, p, s};}else{int id;cin >> id;d[id].is_del = true;d[++idx].is_del = true;d[idx].type=3;}}long long temp1=0,temp2=0;for(int i=1;i<=idx;i++){if(!d[i].is_del) //当前股票没有作废,就统计低于它的卖出数量和高于它的买入数量{temp1=0,temp2=0;for(int j=1;j<=idx;j++){if(!d[j].is_del){if(d[j].type==1 && d[j].price>=d[i].price) temp1+=d[j].num; //买入数量else if(d[j].type==2 && d[j].price<=d[i].price) temp2+=d[j].num; //卖出数量}}long long t=min(temp1,temp2); //取二者最小值if(t>ansn || (t==ansn && d[i].price>ansp)){ansn=t;ansp=d[i].price;}}}printf("%.2lf %lld",ansp,ansn);return 0;}
如果觉得《第三次CCF计算机软件能力认证 集合竞价 (模拟题)》对你有帮助,请点赞、收藏,并留下你的观点哦!