TopcoderArchive
Archive
Algorithm problem

WriterRoyalties

Problem statement, definition, constraints, and public examples.

Problem Statement

Songwriter royalties for commercial music albums are sometimes paid out according to a penny rate. The penny rate is the number of cents the record company pays for each song on each unit sold of an album. The record company pays for a maximum of ten songs per album, regardless of the actual track count. The royalties are paid to the publisher who then gives a certain percentage to the songwriter. Assume that a single songwriter has written all the songs on a particular album. Given the number of songs on the album, the number of units sold, the penny rate, and the percentage given to the songwriter by the publisher, determine how much the songwriter will earn in royalties from album sales.

If the return value is less than $100, it should be formatted as "$XX.XX" (quotes for clarity only), where each X is a single digit. The constraints will guarantee that there are never any fractional cents. If the return value is $100 or higher, it should be formatted as "$X" (quotes for clarity only), where X is the number of dollars with no leading zeros. Cents should be truncated (no rounding). See the examples for more detailed explanations.

Definition

Class:
WriterRoyalties
Method:
royalties
Parameters:
int, int, int, int
Returns:
String
Method signature:
String royalties(int numSongs, int unitsSold, int pennyRate, int royaltyPercentage)
(be sure your method is public)

Constraints

  • numSongs will be between 1 and 30, inclusive.
  • unitsSold will be between 0 and 10000000, inclusive.
  • unitsSold will be divisible by 100.
  • pennyRate will be between 1 and 20, inclusive.
  • royaltyPercentage will be between 1 and 100, inclusive.

Examples

  1. 9
    900000
    8
    50
    Returns: "$324000"
    The album contains 9 songs and sells 900,000 copies. The recording company pays the publisher 8 cents per song per unit sold: 8 * 9 * 900,000 = 64800000 cents = 648000 dollars. 50 percent of this is given to the songwriter.
  2. 13
    100
    6
    62
    Returns: "$37.20"
    The album contains 13 songs, but only 10 songs can count toward the royalties. 100 units were sold, so the record company owes the publisher 10 * 100 * 6 = 6000 cents. 62 percent of 6000 is 3720 cents. Since this value is less than $100, the return value is formatted as "$37.20".
  3. 8
    1000100
    8
    1
    Returns: "$6400"
    Even though the album sells over a million copies, the songwriter only receives $6400 because the publisher keeps 99% of the royalties. The actual amount is $6400.64 but the cents portion is truncated in the return value.
  4. 2
    0
    20
    100
    Returns: "$00.00"
    The return value must always have exactly two digits on both sides of the decimal point.
Back to all problems