Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <algorithm>
- using namespace std;
- void print(long long a, long long b) {
- string s;
- int j = 0;
- if(a)
- {while(a) {
- if(j == 3) {
- j = 0;
- s+= '.';}
- s+= '0' + a%10;
- a/= 10;
- j++;
- }
- reverse(s.begin(), s.end());
- cout << s;
- }
- else
- cout << 0;
- if(b) {
- cout << '.';
- if(b < 10)
- cout << 0 << b;
- else
- cout << b;
- }
- }
- int main()
- {
- string s;
- cin >> s;
- // s = "a1b220.555c0.16d123.156.156.123.60d0.99e100.99";
- long long rub = 0;
- long long cop = 0;
- long long _buf1 = 0;
- long long _buf2 = 0;
- int j = 0;
- s+= 'a';
- bool flag = false;
- for(int i = 0; i < s.size(); i++) {
- if( ('a' <= s.at(i)) && (s.at(i) <= 'z') ) {
- if(flag == 0 && _buf1 == 0) {
- rub += _buf2;
- _buf1 = 0;
- _buf2 = 0;
- continue;
- }
- flag = false;
- if(j == 2) {
- cop+= _buf2;
- rub+= _buf1;
- if(cop >= 100) {
- rub++;
- cop -= 100;
- }
- _buf1 = 0;
- _buf2 = 0;
- }
- else {
- rub+= (_buf1 * 1000) + _buf2;
- _buf1 = 0;
- _buf2 = 0;
- }
- }
- else if(s.at(i) == '.') {
- j=0;
- flag = 1;
- if(j == 4)
- j = 1;
- _buf1*= 1000;
- _buf1+= _buf2;
- _buf2 = 0;
- }
- else {
- if(flag) {
- j++;
- }
- _buf2*= 10;
- _buf2+= s.at(i) - '0';
- }
- }
- print(rub, cop);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement