3wa大佬求调
查看原帖
3wa大佬求调
1262711
houyunjie楼主2024/9/7 17:27
#include <iostream>
#include <cstdio>
using namespace std;
char c,a;
int f=1,now=1,k,b,x;
bool r;
int main()
{
	while(cin>>c)
	{
		if(c=='-') {b+=now*f*x;x=0;f=-1;r=0;}
		if(c=='+') {b+=now*f*x;x=0;f=1;r=0;}
		if(c=='=') {b+=now*f*x;x=0;f=1;now=-1;r=0;}
		if(c>='a'&&c<='z')
		{
			if(r)
			{
				k+=now*f*x;x=0;
			}
			else k+=now*f;
			a=c;r=0;
		}
		if(c>='0'&&c<='9') {x=x*10+c-'0';r=1;}
	}
	b+=now*f*x;
    double ans=double(-b*1.0/k);
	if(ans==-0.0) ans=0;
	printf("a=%.3lf",ans);
	return 0;
}
2024/9/7 17:27
加载中...