萌新求助!!!不知道怎么调整输出,样例外表上能过QAQ
查看原帖
萌新求助!!!不知道怎么调整输出,样例外表上能过QAQ
65917
Slience楼主2020/12/23 23:35
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
using namespace std;
char op;
int n;
int len(int num)
{
	int ans = 0;
	if(num < 0) {
		ans++;
		num = abs(num);
	}
	while(num)
	{
		num/=10;
		ans++;
	}
	return ans;
}
void readin()
{
	char a;
	a = getchar();
	while(a == ' '||a =='\n') a = getchar();
	long long x,y;
	if(a >= 'a' && a <= 'c') op = a;
	else cin.putback(a);
	cin >> x >> y;
	if(op == 'a') cout << x << '+' << y << '=' << x+y << endl << len(x) + len(y) + len(x+y) + 2;
	else if(op == 'b') cout << x << '-' << y << '=' << x-y << endl << len(x) + len(y) + len(x-y) + 2;
	else if(op == 'c') cout << x << '*' << y << '=' << x*y << endl <<len(x) + len(y) + len(x*y) + 2;
	return;
}
int main()
{
	cin >> n;
	while(n--)
	{
		readin();
		if(n != 0) cout << endl;
	}
	return 0;
}

不知道是哪里没有调整好,输出格式似乎不对。运行时间也长的不合理QWQ

2020/12/23 23:35
加载中...