Tap here to switch tabs
Problem
Submissions

Problem: Apply Discount to Prices

med
30 min
Try to solve the Apply Discount to Prices problem.

Statement

A sentence is a string consisting of words separated by a single space. A word represents a price if it starts with the dollar sign '$' followed strictly by one or more digits.

You are given a string sentence and an integer discount. For every word representing a price, apply a discount of discount percent and format the discounted price to exactly 22 decimal places, prefixed by '$'.

Return the modified sentence.

Constraints:

  • 1≤1 \leq sentence.length ≤105\leq 10^5

  • sentence consists of lowercase English letters, digits, ' ', and '$'.

  • sentence does not have leading or trailing spaces.

  • All words in sentence are separated by a single space.

  • All prices will be positive numbers without leading zeros.

  • All prices will have at most 1010 digits.

  • 0≤0 \leq discount ≤100\leq 100

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Apply Discount to Prices

med
30 min
Try to solve the Apply Discount to Prices problem.

Statement

A sentence is a string consisting of words separated by a single space. A word represents a price if it starts with the dollar sign '$' followed strictly by one or more digits.

You are given a string sentence and an integer discount. For every word representing a price, apply a discount of discount percent and format the discounted price to exactly 22 decimal places, prefixed by '$'.

Return the modified sentence.

Constraints:

  • 1≤1 \leq sentence.length ≤105\leq 10^5

  • sentence consists of lowercase English letters, digits, ' ', and '$'.

  • sentence does not have leading or trailing spaces.

  • All words in sentence are separated by a single space.

  • All prices will be positive numbers without leading zeros.

  • All prices will have at most 1010 digits.

  • 0≤0 \leq discount ≤100\leq 100