code force B. Bill Total Value
3638 단어 문자열
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
chipsy48.32televizor12.390
output
12.438.32
input
a1b2c3.38
output
6.38
input
aa0.01t0.03
output
0.04
제목: 48.32는 48달러 32센트(뒤의 두 소수) 12.390달러를 가리키며 정수 부분은 세 자리마다 한 점을 사이에 두고 작은 표 명세서의 모든 금액의 총계를 구한다.
AC 코드:
#include #include #include #include #include using namespace std; #define rep(i,m,n) for(i=m;i<=n;i++) int n, m, k, t; char a[100005]; double sum, zs, xs; int main() {int i, j;scanf("%s", a);int len = strlen(a);a[len] = 'a';rep(i, 0, len){if (isdigit(a[i])){j = i;int cnt = 0;xs = 0; zs = 0;while (isdigit(a[j]) || a[j] == '.')j++;while (a[j - 1] != '.'&&j - 1 > i)cnt++, j--;if (cnt == 2 && j - 1 > i){xs += 0.1*(a[j] - '0') + 0.01*(a[j + 1] - '0');rep(k, i, j - 1) if (isdigit(a[k])) zs = zs * 10 + a[k] - '0';}else if (cnt == 3 && j - 1 > i){rep(k, i, j + 2) if (isdigit(a[k])) zs = zs * 10 + a[k] - '0';}elsefor (k = i; isdigit(a[k]); k++) zs = zs * 10 + a[k] - '0';zs += xs; sum += zs;while (isdigit(a[j]))j++;i = j;}}sprintf(a, "%.2f", sum);len = strlen(a);rep(i, 0, len - 4){printf("%c", a[i]);if (len - 4 - i>0 && (len - 4 - i) % 3 == 0) printf(".");}if (a[len - 1]>'0' || a[len - 2]>'0')printf(".%c%c", a[len - 2], a[len - 1]);system("pause");return 0; }
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
비슷한 이름의 Attribute를 많이 만들어 삭제하는 Houdini사용 소프트웨어는 Houdini16.5입니다 배열에서는 애트리뷰트의 보간이 잘 동작하지 않는 것과 AttributeCreateSOP 노드에서 Size가 4를 넘는 애트리뷰트를 작성해도 값이 조작할 수 없어 의미가 없...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.