Algorithm


B. Bill Total Value
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Vasily exited from a store and now he wants to recheck the total price of all purchases in his bill. The bill is a string in which the names of the purchases and their prices are printed in a row without any spaces. Check has the format "name1price1name2price2...namenpricen", where namei (name of the i-th purchase) is a non-empty string of length not more than 10, consisting of lowercase English letters, and pricei (the price of the i-th purchase) is a non-empty string, consisting of digits and dots (decimal points). It is possible that purchases with equal names have different prices.

The price of each purchase is written in the following format. If the price is an integer number of dollars then cents are not written.

Otherwise, after the number of dollars a dot (decimal point) is written followed by cents in a two-digit format (if number of cents is between 1 and 9 inclusively, there is a leading zero).

Also, every three digits (from less significant to the most) in dollars are separated by dot (decimal point). No extra leading zeroes are allowed. The price always starts with a digit and ends with a digit.

For example:

  • "234", "1.544", "149.431.10", "0.99" and "123.05" are valid prices,
  • ".333", "3.33.11", "12.00", ".33", "0.1234" and "1.2" are not valid.

Write a program that will find the total price of all purchases in the given bill.

Input

The only line of the input contains a non-empty string s with length not greater than 1000 — the content of the bill.

It is guaranteed that the bill meets the format described above. It is guaranteed that each price in the bill is not less than one cent and not greater than 106 dollars.

Output

Print the total price exactly in the same format as prices given in the input.

Examples
input
Copy
chipsy48.32televizor12.390
output
Copy
12.438.32
input
Copy
a1b2c3.38
output
Copy
6.38
input
Copy
aa0.01t0.03
output
Copy
0.04

 



 

Code Examples

#1 Code Example with C++ Programming

Code - C++ Programming

#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;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
chipsy48.32televizor12.390

Output

x
+
cmd
12.438.32
Advertisements

Demonstration


Codeforces Solution-Bill Total Value-Solution in C, C++, Java, Python

Previous
Codeforces solution 1080-B-B. Margarite and the best present codeforces solution
Next
CodeChef solution DETSCORE - Determine the Score CodeChef solution C,C+