本题测评时不知为何额外输出了一个回车,求解答
查看原帖
本题测评时不知为何额外输出了一个回车,求解答
396994
Winston12321_楼主2022/2/4 18:57

错误如图

本人代码:

#include <iostream>
#include <iomanip>
using namespace std;

char ch,let;
long long l,r;
int line,f;

int gete()
{
	int s=0;
	while(true)
	{
		if('0'<=ch && ch<='9') s=s*10+ch-'0';
		else if(ch=='+' || ch=='-' || ch=='=' || ch=='\n') return s;
		else
		{
			let=ch;
			ch=getchar();
			if(!s) s=1;
			return -s-1;
		}
		ch=getchar();
	}
}

void readel()
{
	while(true)
	{
		if(ch=='=') return;
		if(ch=='+')
		{
			f=1;
			ch=getchar();
		}
		else if(ch=='-')
		{
			f=-1;
			ch=getchar();
		}
		line=gete();
		if(line<0) l+=f*(-line-1);
		else r-=f*line;
	}
}

void reader()
{
	while(true)
	{
		if(ch=='\n') return;
		if(ch=='+')
		{
			f=1;
			ch=getchar();
		}
		else if(ch=='-')
		{
			f=-1;
			ch=getchar();
		}
		line=gete();
		if(line>=0) r+=f*line;
		else l-=f*(-line-1);
	}
}

int main()
{
	f=1;
	ch=getchar();
	readel();
	f=1;
	ch=getchar();
	reader();
	float ans=float(r)/float(l);
	cout<<let<<'='<<setiosflags(ios::fixed)<<setprecision(3)<<ans;
	return 0;
}
2022/2/4 18:57
加载中...