-
Notifications
You must be signed in to change notification settings - Fork 3
/
2288.cpp
32 lines (32 loc) · 978 Bytes
/
2288.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
class Solution {
public:
string discountPrices(string sentence, int discount) {
istringstream iss(sentence);
ostringstream oss;
string token;
while (iss >> token) {
if (token[0] != '$') {
oss << token << " ";
continue;
}
bool sign = false;
for (int i = 1; i < token.size(); ++i) {
char c = token[i];
if (c > '9' || c < '0') {
sign = true;
break;
}
}
if (sign || token.size() == 1) {
oss << token << " ";
continue;
}
long long price = stoll(token.substr(1));
double pricePrecise = price * 0.01 * (100 - discount);
oss << "$" << fixed << setprecision(2) << pricePrecise << " ";
}
string ans = oss.str();
ans.pop_back();
return ans;
}
};