求助,在线IDE答案没问题,提交全wa
查看原帖
求助,在线IDE答案没问题,提交全wa
431265
Fresca楼主2022/7/4 21:10

rt,代码如下

#include <cstdio>
#include <algorithm>
using namespace std;
char ch;
int la=0,ra=0,lx=0,rx=0,a,x;
char let;
bool run=true;
void work(int mode)
{
	int f=1;
	if((ch=='=')||!run)
		return;
	if(ch=='-')
		f=-1;
	if(run)
    	ch=getchar();
	int x=0;
	bool num=true;
	while(!((ch=='+')||(ch=='-')||(ch=='=')||!run))
	{
		if((ch>='a')&&(ch<='z'))
		{
			let=ch;
			num=false;
		}
		if(num)
		    x=x*10+ch-'0';
		if((ch=getchar())==EOF)
			run=false;
	}
	if(mode==1)
		if(num)
			la=la+x*f;
		else
			lx=lx+max(1,x)*f;
	else
		if(num)
			ra=ra+x*f;
		else
			rx=rx+max(1,x)*f;
	work(mode);
	return;
}
int main()
{
	work(1);
	ch=1;
	work(2);
	a=ra-la;
	x=lx-rx;
	if(a==0)
		printf("%c=0.000",let);
	else
		printf("%c=%.3lf",let,(a*1.0)/x);
	return 0;
}

提交记录

2022/7/4 21:10
加载中...