Beer Bill[CTU Open Contest 2019][ceil函数]

14 篇文章 0 订阅
5 篇文章 0 订阅

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. 

 <BILL> ::= <LINE> | <LINE><BILL>

 <LINE> ::= <PRICED_LINE><line_break> | <RAKE_LINE><line_break>

 <PRICED_LINE> ::= <PRICE_SPEC> | <PRICE_SPEC><RAKE> 

 <RAKE_LINE> ::= <RAKE> 

<PRICE_SPEC> ::= <PUB_INTEGER><comma><hyphen> 

 <RAKE> ::= <rake_dent> | <rake_dent><RAKE>

 <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 

<comma> ::= ’,’ // ascii character 44 

 <hyphen> ::= ’-’ // 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 <PUB INTEGER> 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,-

rounded up to the nearest 10s
注意了注意了,这个“nearest 10s”它是四舍五入没错,但是它取的是最大值,4.1取5的那种,-2.1取-2,使用ceil函数进行四舍五入。
在这题里进行的是个位的四舍五入,所以先将ans/10.0转化为小数

ac代码:

#include<iostream>
#include<string.h>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<iomanip>
using namespace std;
int main()
{
    long long ans=0;
    string s;
    while(getline(cin,s))
    {    if(s[0]=='|')
        ans+=s.size()*42;
     else
     {
         int len=s.size();
         int d=0;
         for(int i=0;i<len;i++)
         {
             if(s[i]==',')
             {
                 d=i;
                 break;
             }
         }
         int v=0;
         int t=d;
         for(int i=0;i<d;i++)
         {
             v+=(s[i]-'0')*pow(10,t-1);
             //cout<<v<<"v"<<endl;
             t--;
             //cout<<t<<endl;
         }
         //cout<<v<<endl;
         len=len-d-2;
         //cout<<len<<endl;
         ans+=v*len;
         //cout<<ans<<endl;
     }
  }
    if(ans<10)
    {
      cout<<"10,-";
    }
    else
    {
      double n=(double)ans/10.0;
      ans=ceil(n)*10;
      cout<<ans<<",-";
    }
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Norton's Beer函数是指将一个电路网络转化为一个等效的电流源和电阻的组合。这个方法被广泛应用在电子电路分析中,特别是在直流电路和交流电路的分析过程中。 Norton's Beer函数被用来简化复杂的电路问题,通过将电路中的各种元件转化为一个等效的电阻与电流源的组合,从而简化了电路分析的过程。 具体地说,Norton's Beer函数将一个电路的电流源通过戴上一定大小的负载电阻来模拟,这样就可以用一个等效的电流源来代替原来的电路中的电流源。这个等效的电流源称为Norton电流源,它的大小等于原来电路中的电流源的大小,并且与原电路中的电流源的极性一致。 同时,Norton's Beer函数还将电路中的各种元件转化为一个等效的电阻。这个等效电阻称为Norton电阻,它的大小等于原来电路中某一节点处的电压与原电流源大小的比值。 通过对电路中的各个元件进行Norton's Beer函数的转换,我们可以得到一个简化的等效电路,其中只包含了一个电流源和一个电阻。这样,通过对这个简化的等效电路进行分析,我们可以得到与原电路相同的结果,同时减少了计算的复杂度。 总之,Norton's Beer函数是一种在电路分析中常用的方法,它通过将电路中的各个元件转化为一个等效的电流源和电阻的组合,简化了电路的分析过程,提高了计算的效率。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值