CTU Open Contest 2019 B. Beer Bill

↘锁芯ラ 提交于 2020-02-23 12:25:29

题目来源:点击这里
题目如下:
Pub bills were introduced into daily life long before computers even existed. People tend tothink that once a bill has been paid, it is no more than a pathetic paper scrap not worthy ofany more attention. The fact, completely overlooked by established computer science streams,is that the scribblings on the bill represent highly formalized and often quite nontrivial textsuitable for many formal language applications and analyses.
A bill consists of lines of characters. Each line is either a priced line or a rake line. A pricedline begins with a positive integer — the price of a food or drink item — which is optionallyfollowed by some number of vertical bars. The price of the line is calculated as follows: If thebars are present, the price of the line is equal to the item price multiplied by the number ofbars. Otherwise, the price of the line is equal to the price of the item. A rake line containsonly vertical bars (similar to rake dents, hence the name rake line), each bar stands for one beerbought by the bill holder. The price of the rake line is the price of one beer multiplied by thenumber of the bars on the line. The beer price, in this problem, is equal to 42 monetary units.The bill total is the total of prices of all lines on the bill.
We present you with a formal defifinition of the so-called Raked bill language, as far as we know,the fifirst of its kind in the whole history of computer science. The bills in this problem areexpressed in the Raked bill language.
::= |
::= <PRICED_LINE><line_break> | <RAKE_LINE><line_break>
<PRICED_LINE> ::= <PRICE_SPEC> | <PRICE_SPEC>
<RAKE_LINE> ::=
<PRICE_SPEC> ::= <PUB_INTEGER>
::= <rake_dent> | <rake_dent>
<PUB_INTEGER> ::= <dig_1_9> | <dig_1_9><DIG_SEQ>
<DIG_SEQ> ::= <dig_0_9> | <dig_0_9><DIG_SEQ>
<dig_1_9> ::= ’1’ | ’2’ | ’3’ | ’4’ | ’5’ | ’6’ | ’7’ | ’8’ | ’9’
<dig_0_9> ::= ’0’ | <dig_1_9>
<rake_dent> ::= ’|’ // ascii character 124
::= ’,’ // ascii character 44
::= ’-’ // ascii character 45
<line_break> ::= LF // ascii character 10, line feed
In the language specifification above, the actual characters which appear on the bill are enclosedin single quotation marks to distinguish them from the other parts of the specifification. Thesymbol // introduces a single line comment, it is not part of the language defifinition.
Input Specifification
The input contains a nonempty sequence of lines which specify a bill. Each input line is eithera priced line or a rake line. A priced line starts with a positive integer, not exceeding 1 000,followed immediately by a comma and a minus sign. Optionally, the minus sign is followed bya nonzero number of vertical bars. A rake line contains nonzero number of vertical bars andno other symbols. In the whole bill, the vertical bar is represented as ’|’, ascii character 124.Each line contains at most 1 000 characters, there are no blanks on the line. There are at most1 000 input lines. The input does not contain any empty line. All prices are expressed in thesame monetary units.
Output Specifification
Output a single number — the bill total rounded up to the nearest 10s. The number shouldbe in the format, that is, it should be immediately followed by a comma and aminus sign.
样例输入1:

||||
123,-|||

样例输出1:

540,-

样例输入2:

|||
12,-|
|||
12,-||
10,-|

样例输出2:

300,-

样例输入3:

|
8,-|

样例输出3:

50,-
/*这道题最坑的地方应该在于最后的sum取值,刚开始读题的时候一直认为是四舍五入,后来才知道,酒店是不会少收钱的,也就是说,541~549都要按550收钱*/
#include<algorithm>
#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<cctype>
using namespace std; 
int main(){
	char a[10005];
	long long sum=0;
	while(scanf("%s",a)!=EOF){
		if(a[0]==124){
			sum+=42*strlen(a);
		}
		else{
			int i,s=0;
			for(i=0;i<strlen(a);i++){
                if(a[i]==','&&a[i+1]=='-')
                    break;
				s=s*10+(a[i]-'0');
			}
			sum=sum+s*(strlen(a)-2-i);
		}
		getchar();
        memset(a,0,sizeof(a));
	}
    //if(sum%10<5)
		//sum=sum/10*10;
    //else{
    //if(sum%10>4){
    	if(sum%10)
        	sum=sum/10*10+10;
    //}
   // }
	printf("%lld,-",sum);
	return 0;
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!