当前位置:网站首页>* 5-2 CCF 2014-12-3 call auction
* 5-2 CCF 2014-12-3 call auction
2022-08-09 14:51:00 【Ye Xiaobai】
题目描述

源代码
#include<iostream>
#include<cstring>
#include<vector>
using namespace std;
const int N = 5000;
struct Order
{
double price;
int num;
int sell;//交易状态:0-买入 1-卖出 -1 取消
} order[N + 1];
vector<double> pricevec;//Save all occurrences of prices
int main()
{
char s[10];
int num = 0, t; //numThe total number of recorded data
while (cin >> s) //buy 9.25 100
{
if (s[0] == 'c')//读入的是cancel
{
cin >> t;
order[t - 1].sell = -1;//取消第iline of transactions
order[num].sell = -1;//cancelInstructions must also occupy one
}
else
{
cin >> order[num].price >> order[num].num;
if (s[0] == 's')//卖出
order[num].sell = 1;
else
order[num].sell = 0;
pricevec.push_back(order[num].price);
}
num++;
}
double ans = 0;//开盘价
long long maxn = 0;//Save the maximum transaction volume
for (int i = 0; i < pricevec.size(); i++)
{
long long num_s = 0;//The number of shares available for sale
long long num_b = 0;//The number of shares available for purchase
for (int j = 0; j < num; j++)
{
if (order[j].sell == 1 && order[j].price <= pricevec[i])
num_s += (long long)order[j].num;
}
for (int j = 0; j < num; j++)
{
if (order[j].sell == 0 && order[j].price >= pricevec[i])
num_b += (long long)order[j].num;
}
num_s = min(num_s, num_b);
if (num_s > maxn)
{
maxn = num_s;
ans = pricevec[i];
}
else
{
if (num_s == maxn)
ans = max(ans, pricevec[i]);
}
}
printf("%.2f %lld\n", ans, maxn);
return 0;
}
边栏推荐
猜你喜欢
随机推荐
RHCE Course Summary
C语言中的 递归问题 以及将递归改写成非递归。(解析常见的几个递归题目及代码) 求阶乘、求斐波那契、汉诺塔、
dpkg:错误:无法新建文件 ‘/var/lib/dpkg/info/format-new’: 没
*1-1 OJ 56 Hamming Distance
shell课程总结
Dry+Bean+Dataset R language data analysis, report in English
“未来10年,中国APP不可能回印度了”
汇编语言学习(一)
*5-2 CCF 2014-12-3 集合竞价
【LeetCode】1413. 逐步求和得到正数的最小值
*4-1 CCF 2014-12-1门禁系统
源码编译安装LAMP
RHCE课程总结
C语言 交换两个变量(不创建临时变量) 代码详解
Thinking about oracle financial data authority
Small program template production process, small program template production is convenient and fast
小程序程序开发怎么做?应以突出功能为主
#23-5 OJ 86 杨辉三角形
实现H5网页授权
C语言中常用的数组排序方法:冒泡排序、选择排序、插入排序、数组的移动(含代码详解)以及相关联系题









