25分求助
查看原帖
25分求助
1311900
Greeper楼主2024/7/25 15:20

刚发完函数就WA

#include<bits/stdc++.h>
using namespace std;
int n;
string a,b,c,d;
char f;
int math(string a)
{
    int l=a.size();
    int x=0;
    for(int i=0;i<l;i++)
    {
        x*=10;
        x+=int(a[i]-'0');
    }
    return x;
}
string str(int a)
{
	string y,x;
	while(a)
	{
		y+=char(a%10+'0');
		a/=10;
	}
	for(int i=y.size()-1;i>=0;i--)
	{
		x+=y[i];
	}
	return x;
}
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a;
		if(a[0]>='a'&&a[0]<='c')
		{
			f=a[0];
			cin>>b>>c;
		}
		else
		{
			b=a;
			cin>>c;
		}
		if(f=='a')
		{
			cout<<b<<'+'<<c<<'='<<math(b)+math(c)<<endl;
			cout<<b.size()+c.size()+2+str(math(b)+math(c)).size()<<endl;
		}
		if(f=='b')
		{
			cout<<b<<'-'<<c<<'='<<math(b)-math(c)<<endl;
			cout<<b.size()+c.size()+2+str(math(b)-math(c)).size()<<endl;
		}
		if(f=='c')
		{
			cout<<b<<'+'<<c<<'='<<math(b)*math(c)<<endl;
			cout<<b.size()+c.size()+2+str(math(b)*math(c)).size()<<endl;
		}
	}
	return 0;
}
2024/7/25 15:20
加载中...