December 14 CCF Real title 3-set bid

Source: Internet
Author: User

Problem description

  A stock exchange invites you to write a program that determines the opening and opening volume of a particular stock based on an order submitted by a pre-opening customer.

The input of the program consists of a number of lines, each of which has a record that may have the following types of records:

1. Buy P s represents the purchase price of a stock, each bid is p and the number of shares purchased is S.
2. Sell P S represents a sell order for the sale of shares, with a bid of p for each hand and a sale of shares of S.
3. Cancel I means that the record of line I is revoked. If the open price is P0, the system can bid for at least P0 and all bids up to

Match the sell order for P0. As a result, the opening volume at this time is a small value between the total number of bids at least P0 and the total number of shares of all bids up to p0.

Your program needs to determine an open price so that the opening volume is as large as possible. If there are multiple open prices that match the conditions, your program should output the highest one.
Input format

The input data has any number of lines, and each row is a record. Ensure that the input is valid. The number of shares is a positive integer not exceeding 108, and the bid is accurate to the positive real number of two digits after the decimal point, and not more than 10000.00.
Output format

  You need to output a line that contains two numbers, separated by a space. The first number is the open price and the second is the volume under this open price. The opening price needs to be exactly two digits after the decimal point.

Input sample
Buy 9.25 100
Buy 8.88 175
Sell 9.00 1000
Buy 9.00 400
Sell 8.92 400
Cancel 1
Buy 100.00 50
Output sample
9.00 450
Measuring use case size and conventions
For 100% of data, the number of rows entered does not exceed 5000.

There's no way to cancel a cancellation order.

#include <iostream>#include<vector>#include<map>#include<iomanip>using namespacestd;classLine//defining data structure storage directives{ Public:    stringAction; Doublep; ints;};intMain () {intnum=0;//under the Mac with Clion write, seemingly do not recognize CTRL + Z and CTRL (command) +d, had to manually enter the number of linesCin>>num; string inch; Map<Double,int,greater<Double>> buy;//Store purchases in descending order for each price of buymap<Double,int> Sell;//stores the amount of sell for each price in ascending orderVector<line*>v;  for(intI=0; i<num;i++) {cin>>inch; if(inch=="buy")        {            DoubleA; intb; CIN>>a>>b; Buy[a]+=b; Line*temp =NewLine ; Temp->action ="buy"; Temp->p =A; Temp->s =b;     V.push_back (temp); //Storage Instructions        }        Else if(inch=="Sell")        {            DoubleA; intb; CIN>>a>>b; Sell[a]+=C; Line*temp =NewLine ; Temp->action ="Sell"; Temp->p =A; Temp->s =b;     V.push_back (temp); //Storage Instructions        }        Else        {   intN//undo instruction, subtract the corresponding amount from the mapCin>>N; N--; DoubleA = v[n]->p; intb = v[n]->s; if(v[n]->action=="buy") Buy[a]-=b; ElseSell[a]-=b; }    }    Doublep=0;//define P and s    ints=0;  for(map<Double,int>::iterator it = Sell.begin (); It!=sell.end (); it++)    {     //for sell from small to large scan        inttemp=0;//define three temporary values to store volume        inttemp1=0; intTemp2=0;  for(map<Double,int>::iterator IIT = Sell.begin (); Iit!=sell.end (); iit++)        {     //calculate the total number of orders sold for up to P0            if(iit->first<=it->First ) Temp1+=iit->second; Else                 Break; }         for(map<Double,int>::iterator IIT = Buy.begin (); Iit!=buy.end (); iit++)        {     //calculates the total number of shares for which the bid is at least p0            if(iit->first>=it->First ) Temp2+=iit->second; Else                 Break; } temp=min (TEMP1,TEMP2); if(temp>=S) {P= it->First ; S=temp; }} cout<<fixed<<setprecision (2) <<P<<" "<<S;//formatted output    return 0;}

December 14 CCF Real title 3-set bid

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.