せいしゅん404 • 4年前
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
#define N 10010
struct node{
int v;
double c;
};
node a[N];
int main(void){
int n,top=1;
char ch;
cin>>a[top].v>>a[top].c>>n;
while(n--){
cin>>ch;
if(ch=='Z'&&top>1){
top--;
}
if(ch=='P'){
top++;
cin>>a[top].v>>a[top].c;
a[top].v=a[top-1].v+a[top].v;
a[top].c=(a[top-1].c*a[top-1].v+(a[top].v-a[top-1].v)*a[top].c)/a[top].v;
}
printf("%d %.5lf\n",a[top].v,a[top].c);
}
return 0;
}
评论:
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
#define N 10010
struct node{
int v;
double c;
};
node a[N];
int main(void){
int n,v,c,top=1;
char ch;
cin>>a[top].v>>a[top].c>>n;
while(n--){
cin>>ch;
if(ch=='Z'&&top>1){
top--;
}
if(ch=='P'){
top++;
cin>>v>>c;
a[top].v=a[top-1].v+v;
a[top].c=(a[top-1].c*a[top-1].v+c*v)/(double)a[top].v;
}
printf("%d %.5lf\n",a[top].v,a[top].c);
}
return 0;
}
请先登录,才能进行评论