1234

1234

/ 0评 / 920次 / 0
/*
 * @Author: Gehrychiang
 * @LastEditors  : Gehrychiang
 * (1)初始化栈  stack<int>vis ,定义一个栈
(2)入栈  vis.push(x) 
(3)出栈  vis.pop()       
(4)判断是否为空 vis.empty()
(5)判断栈中元素的数量vis.size()
(6)得到栈的栈顶元素  vis.top()
 * @Website: www.yilantingfeng.site
 * @E-mail: gehrychiang@aliyun.com
 */
#include <bits/stdc++.h>
using namespace std;
double vtmp[10005];
double ctmp[10005];
int main()
{
    stack<double>v;
    stack<double>c;
    stack<double>tmp;
    double v0,c0;
    cin>>v0>>c0;
    int n;
    cin>>n;
    for (int t = 0; t < n; t++)
    {
        char tmp;
        cin>>tmp;
        if(tmp=='P')
        {
            double a,b;
            cin>>a>>b;
            v.push(a);
            c.push(b);
        }
        else if(tmp=='Z')
        {
            if(!v.empty())
            {
                v.pop();
            }
            if(!c.empty())
            {
                c.pop();
            }
        }


        memset(vtmp,0,sizeof(vtmp));
        memset(ctmp,0,sizeof(ctmp));
        int tolv=0;
        double tolc=0;
        int s=v.size();
        for (int i = 0; i < s; i++)
        {
            vtmp[i]=v.top();
            v.pop();
            ctmp[i]=c.top();
            c.pop();
            tolv+=vtmp[i];
            tolc+=vtmp[i]*ctmp[i];
        }
        printf("%d %.5lf\n",tolv+(int)v0,(tolc+v0*c0)/((tolv+v0)));
        //cout<<tolv+v0<<" "<<(tolc+v0*c0)/((tolv+v0))<<endl;
        for (int i = s-1; i >=0 ; i--)
        {
            v.push(vtmp[i]);
            c.push(ctmp[i]);
        }
        
        


    }
    
    return 0;
}

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

你好 No.74987