全WA,蒟蒻求助!
查看原帖
全WA,蒟蒻求助!
48831
Vegiak楼主2020/8/16 07:50

乱七八糟的代码

#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
int n,m;
int main()
{
	cin>>n;
	cin.get();
	for(int i=1;i<=n;i++)
	{
		string s;
		int k=1,dig[3]={0,0,0},ans,res,fu=0;
		getline(cin,s);
		ans=s.length();
		for(int j=0;j<s.length();j++)
		{
			if(s[j]>='a'&&s[j]<='c')
			{
				m=s[j]=s[j]-'a'+1;
				ans-=2;
				j++;
				continue;
			}
			if(s[j]==' ')
			{
				k=2;
				continue;
			}
			if(s[j]=='-')
			{
				fu=1;
				continue;
			}
			dig[k]*=10;
			dig[k]+=s[j]-'0';
			if(fu==1)
			{
				fu=0;
				dig[k]+=-1;
			}
		}
		cout<<dig[1];
		if(m==1)
		{
			res=dig[1]+dig[2];
			cout<<"+"<<dig[2]<<"="<<res<<endl;
		}
		if(m==2)
		{
			res=dig[1]-dig[2];
			cout<<"-"<<dig[2]<<"="<<res<<endl;
		}
		if(m==3)
		{
			res=dig[1]*dig[2];
			cout<<"*"<<dig[2]<<"="<<res<<endl;
		}
		if(res<0)ans++;
		while(res)
		{
			res/=10;
			ans++;
		}
		ans++;
		if(dig[1]<0)ans++;
		if(dig[2]<0)ans++;
		cout<<ans<<endl;
	}
	return 0;
}
2020/8/16 07:50
加载中...