求调
查看原帖
求调
257173
rish楼主2024/9/3 23:31

样例都过了,第一个点在本地也过了,为什么交上去就是全WA

#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+10;
string s;
char ch;
int q[N], q2[N], x1[N], x2[N], pos1[N], pos2[N];
int h, hx1, hx2, anst=0, t, pd;
int main()
{
	getline(cin, s);
	for(int i=0;i<s.size();i++)
	{
		if(s[i]>='a'&&s[i]<='z')
		{
			ch = s[i];
			if(!pd) 
			{
				x1[++hx1] = max(t, 1), pos1[hx1] = h+1, t = 0;	
				if(q2[h]==2) x1[hx1]*=-1;
			}
			else 
			{
				x2[++hx2] = max(t, 1), pos2[hx2] = h+1, t = 0;
				if(q2[h]==2) x2[hx2]*=-1;
			}
		}
		else if(s[i]=='+')
		{
			q[++h] = t;
			q2[h] = 1;
			t = 0;
		}
		else if(s[i]=='-') q[++h] = t, q2[h] = 2, t = 0;
		else if(s[i]=='=')
		{
			pd = h+1;
			q[++h] = t;
			q2[h] = 3;
			t = 0;
		}
		else t = t*10+(s[i]-'0');
	}
	if(pos2[hx2]!=h) q[++h] = t;
	int now = 1, ans1 = 0, ans2 = 0;
	for(int i=1;i<=pd;i++)
	{
		if(now==1) ans1 = ans1+q[i];
		if(now==2) ans1 = ans1-q[i];
		now = q2[i];
	}
	now = 1;
	for(int i=pd+1;i<=h;i++)
	{
		if(now==1) ans1 = ans1-q[i];
		if(now==2) ans1 = ans1+q[i];
		now = q2[i];
	}
	while(hx1) anst -= x1[hx1], hx1--;
	while(hx2) anst += x2[hx2], hx2--;
	double tt = double(ans1)/double(anst);
	cout << ch << '=';
	if(tt==-0.0) puts("0.000");
	else cout << fixed << setprecision(3) << double(ans1)/double(anst);
	return 0;
}
2024/9/3 23:31
加载中...