0分求助
查看原帖
0分求助
1095479
Wangyicheng2023楼主2024/6/11 19:14
#include<bits/stdc++.h>
using namespace std;
int main()
{
	char a;
	int fh=1;
	double xs1=0,xs2=0;
	double cs1=0,cs2=0;
	int temp=0;
	char x;
	
	while(1)
	{
		a=getchar();
		if(a=='='){
		cs1+=temp;	
		break;
		}
		else if(a=='-')
		{
		fh=0;
		cs1+=temp;
		temp=0;
		}
		else if(a=='+'){
		fh=1;
		cs1+=temp;
		temp=0;
	}
		else if(a>='0'&&a<='9')
		{
			if(fh)
			temp=temp*10+int(a-48);
			else
			temp=temp*10-int(a-48);
		}
		else 
		{
		xs1+=temp;
		temp=0;
		x=a;
		}
	}
	temp=0;
	fh=1;
	
	while(1)
	{
		cin.get(a);
		if(a=='\n'){
		cs2+=temp;	
		break;
		}
		else if(a=='-')
		{
		fh=0;
		cs2+=temp;
		temp=0;
		}
		else if(a=='+'){
		fh=1;
		cs2+=temp;
		temp=0;
	}
		else if(a>='0'&&a<='9')
		{
			if(fh)
			temp=temp*10+int(a-48);
			else
			temp=temp*10-int(a-48);
		}
		else 
		{
		xs2+=temp;
		temp=0;
		x=a;
		}
	}
	
	//cout<<x<<" "<<cs1<<" "<<xs1;
	//cout<<endl<<" "<<cs2<<" "<<xs2;
	
	double ans;
	ans=(cs1-cs2)/(xs2-xs1);
	cout<<x<<"=";
	printf("%.3lf",ans);
	return 0;
}
2024/6/11 19:14
加载中...