6 kyu

Ease the StockBroker

327 of 2,180g964

Description:

Clients place orders to a stockbroker as strings. The order can be simple or multiple or empty.

Type of a simple order: Quote/white-space/Quantity/white-space/Price/white-space/Status

where Quote is formed of non-whitespace character, Quantity is an int, Price a double (with mandatory decimal point "." ), Status is represented by the letter B (buy) or the letter S (sell).

Example:

"GOOG 300 542.0 B"

A multiple order is the concatenation of simple orders with a comma between each.

Example:

"ZNGA 1300 2.66 B, CLH15.NYM 50 56.32 B, OWW 1000 11.623 B, OGG 20 580.1 B"

or

"ZNGA 1300 2.66 B,CLH15.NYM 50 56.32 B,OWW 1000 11.623 B,OGG 20 580.1 B"

To ease the stockbroker your task is to produce a string of type

"Buy: b Sell: s" where b and s are 'double' formatted with no decimal, b representing the total price of bought stocks and s the total price of sold stocks.

Example:

"Buy: 294990 Sell: 0"

Unfortunately sometimes clients make mistakes. When you find mistakes in orders, you must pinpoint these badly formed orders and produce a string of type:

"Buy: b Sell: s; Badly formed nb: badly-formed 1st simple order ;badly-formed nth simple order ;"

where nb is the number of badly formed simple orders, b representing the total price of bought stocks with correct simple order and s the total price of sold stocks with correct simple order.

Examples:

"Buy: 263 Sell: 11802; Badly formed 2: CLH16.NYM 50 56 S ;OWW 1000 11 S ;"

"Buy: 100 Sell: 56041; Badly formed 1: ZNGA 1300 2.66 ;"

Notes:

  • If the order is empty, Buy is 0 and Sell is 0 hence the return is: "Buy: 0 Sell: 0".
  • Due to Codewars whitespace differences will not always show up in test results.
  • With Golang (and maybe others) you can use a format with "%.0f" for "Buy" and "Sell".
Fundamentals
Strings

More By Author:

Check out these other kata created by g964

Stats:

CreatedFeb 13, 2015
PublishedFeb 14, 2015
Warriors Trained10287
Total Skips2842
Total Code Submissions34888
Total Times Completed2180
Java Completions327
C# Completions195
JavaScript Completions443
Python Completions502
Ruby Completions97
CoffeeScript Completions8
Clojure Completions26
Haskell Completions27
C++ Completions95
PHP Completions95
C Completions59
TypeScript Completions64
Swift Completions84
Crystal Completions3
R Completions15
Shell Completions21
OCaml Completions12
Julia Completions8
Scala Completions28
Go Completions56
Rust Completions44
F# Completions13
Kotlin Completions40
Groovy Completions14
Lua Completions23
Pascal Completions2
Perl Completions8
D Completions5
Total Stars216
% of votes with a positive feedback rating78% of 456
Total "Very Satisfied" Votes306
Total "Somewhat Satisfied" Votes103
Total "Not Satisfied" Votes46
Ad
Contributors
  • g964 Avatar
  • ZozoFouchtra Avatar
  • joh_pot Avatar
  • ChristianECooper Avatar
  • imjasonmiller Avatar
  • kazk Avatar
  • Blind4Basics Avatar
  • Voile Avatar
  • monadius Avatar
  • hobovsky Avatar
  • trashy_incel Avatar
  • user8436785 Avatar
  • Just4FunCoder Avatar
  • saudiGuy Avatar
Ad