StockQuotes
SRM 257 · 2005-08-08 · by lars2520
Problem Statement
You will be given a
Constraints
- Each element of quotes will be formatted as "EXCHANGE BID ASK" where EXCHANGE is a digit between '0' and '9', inclusive, and BID and ASK are integers between 1 and 1000, inclusive, without leading zeros.
- quotes will contain between 1 and 50 elements inclusive.
- An exchange will never issue a quote that is the same is its existing quote (so the number of times that its quote changes will be identical to the number of quotes it issues).
- ASK will be greater than BID in each element of quote.
- The inside spread will always be greater than 0.
Statement by TopCoder, Inc. — view the original on the archive.
{"0 10 14",
"1 9 16",
"2 11 15",
"0 11 13",
"1 10 15",
"2 12 14",
"0 9 15",
"2 8 20"}
Returns: {"0 3 4.00", "1 2 6.00", "2 3 6.00", "10 6 2.83" }
The following table shows how the best bid and ask change as new bids come in: | BEST Exch|Bid |Ask | Bid|Ask | Changed ----+----+----+----+----+------ 0 | 10 | 14 | 10 | 14 | Yes 1 | 9 | 16 | 10 | 14 | 2 | 11 | 15 | 11 | 14 | Yes 0 | 11 | 13 | 11 | 13 | Yes 1 | 10 | 15 | 11 | 13 | 2 | 12 | 14 | 12 | 13 | Yes 0 | 9 | 15 | 12 | 14 | Yes 2 | 8 | 20 | 10 | 15 | Yes
{"1 68 72","1 65 71","0 64 77","2 65 76","1 65 77","0 66 77","5 64 77","8 67 75","1 67 74","1 64 77"}
Returns: {"0 2 12.00", "1 5 8.40", "2 1 11.00", "5 1 13.00", "8 1 8.00", "10 7 7.71" }
{"8 931 944",
"8 926 946",
"8 926 951",
"8 928 953",
"8 929 954"}
Returns: {"8 5 21.60", "10 5 21.60" }
{"6 796 804","0 796 802","8 796 811","7 791 809","7 796 805","9 793 805","5 793 807","8 794 803","1 787 805","5 786 802","8 790 807","6 793 803","3 792 802","6 790 802","6 789 800","8 796 805","1 788 802","8 790 801","8 791 801","8 790 803","7 792 804","2 790 801","9 790 804","2 791 802","0 786 803","1 786 799","5 783 801","2 792 800","8 787 804","1 792 806","7 790 800","6 791 802","2 791 806"}
Returns: {"0 2 11.50", "1 4 14.75", "2 4 11.25", "3 1 10.00", "5 3 16.00", "6 5 10.40", "7 4 12.25", "8 8 12.63", "9 2 13.00", "10 6 6.83" }
{"0 639 648",
"9 640 651",
"5 638 650",
"9 637 651",
"6 637 652",
"8 638 653",
"7 637 651",
"6 635 652",
"3 636 653",
"1 634 653",
"0 635 654",
"4 635 654",
"3 634 652",
"0 635 655",
"5 635 653"}
Returns: {"0 3 16.00", "1 1 19.00", "3 2 17.50", "4 1 19.00", "5 2 15.00", "6 2 16.00", "7 1 14.00", "8 1 15.00", "9 2 12.50", "10 5 10.20" }
Submissions are judged against all 65 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class StockQuotes with a public method vector<string> report(vector<string> quotes) · 65 test cases · 2 s / 256 MB per case