-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy path727B. Bill Total Value.cpp
116 lines (95 loc) · 1.97 KB
/
727B. Bill Total Value.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
vector<string> nums;
long long a = 0, b = 0;
string s;
cin >> s;
for (int i = 0, sLen = s.length(); i < sLen; i++) {
if (!isdigit(s[i])) {
while (!isdigit(s[i++])) {}
i -= 2;
}
else {
string tmp = "";
int dots = 0;
while (isdigit(s[i]) || s[i] == '.') {
tmp += s[i++];
if (s[i] == '.') dots++;
}
if (dots > 1) {
for (int j = 0, tmpLen = tmp.length(); j < tmpLen && dots > 1; j++)
if (tmp[j] == '.') {
tmp.erase(j++, 1);
dots--;
}
int dotLoc = tmp.find('.') + 1;
if (tmp.length() - dotLoc == 3)
tmp.erase(--dotLoc, 1);
}
else {
int dotLoc = tmp.find('.') + 1;
if (dotLoc && tmp.length() - dotLoc == 3)
tmp.erase(--dotLoc, 1);
}
nums.push_back(tmp);
}
}
for (int i = 0, numsLen = nums.size(); i < numsLen; i++) {
stringstream ss(nums[i]);
int tmp1 = 0, tmp3 = 0;
char tmp2;
ss >> tmp1 >> tmp2 >> tmp3;
a += tmp1;
b += tmp3;
}
while (b > 99) {
b -= 100;
a++;
}
vector<int> res;
while (a != 0) {
int fthreeDigit = a % 1000;
res.push_back(fthreeDigit);
a /= 1000;
}
if (res.size()) {
reverse(res.begin(), res.end());
for (int i = 0; i < res.size() - 1; i++) {
if (res[i] == 0) {
cout << "000.";
}
else {
if (i != 0 && res[i] < 100)
cout << 0;
if (i != 0 && res[i] < 10)
cout << 0;
cout << res[i] << ".";
}
}
if (res[res.size() - 1] == 0) {
cout << "000";
}
else {
if (res.size() != 1 && res[res.size() - 1] < 100)
cout << 0;
if (res.size() != 1 && res[res.size() - 1] < 10)
cout << 0;
cout << res[res.size() - 1];
}
}
else {
cout << a;
}
if(b)
if (b < 10)
cout << ".0" << b;
else
cout << '.' << b;
cout << endl;
return 0;
}