Apply Discount to Prices LeetCode solution in C++
1class Solution {2public:3string discountPrices(string sentence, int discount) {4// doit is a function5auto doit = [&](string word) {6int n(size(word));7if (word[0] != '$' or n == 1) return word;89long long price = 0;10for (int i = 1; i < n; i++) {11if (!isdigit(word[i])) return word;12price = price * 10 + (word[i] - '0');13}1415stringstream ss2;16double discountPercentage = (100 - discount) / 100.0;17ss2 << fixed << setprecision(2) << (discountPercentage * price);18return "$" + ss2.str();19};2021string word, res;22stringstream ss(sentence);2324while (ss >> word) {25res += doit(word) + " ";26}2728res.pop_back();29return res;30}31};