求助:自测全过,洛谷全wa,在洛谷的IDE上测试能过
查看原帖
求助:自测全过,洛谷全wa,在洛谷的IDE上测试能过
47458
生生流转楼主2020/10/15 14:24
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std;
char s[1000];
int x=0, y=0, cases,n;
int length(int xx) {
	int l=0,f=-1;
	if (xx >= 0) f = 1;
	while (xx  != 0) {
		l++;
		xx = xx / 10;
	}
	if (f==1) return l;
	else  return l+1;
}
void get(int start) {
	n = strlen(s);
	int post = start ;
	while (s[post]!= ' ') post++;
	for (int i = start; i < post; i++) x = x * 10 + s[i] - 48;
	for (int i = post + 1; i < n; i++) y = y * 10 + s[i] - 48;
}
int main() {
	scanf("%d\n", &cases);
	int flag = 0, elseflag;
	for (int i = 1; i <= cases; i++) {
		elseflag = 0;
		gets(s);
		if (s[0] == 'a') flag = 1; 
		else if (s[0]=='b') flag = 2;
		else if (s[0] == 'c') flag = 3;
		else elseflag = 1;
		if (elseflag == 0) get(2);
		else get(0);
		if(flag==1)
			printf("%d+%d=%d\n%d\n", x, y, x + y, length(x) + length(y) + length(x + y) + 2);
		if (flag==2) 
			printf("%d-%d=%d\n%d\n", x, y, x - y, length(x) + length(y) + length(x - y) + 2);
		if (flag==3) 
			printf("%d*%d=%d\n%d\n", x, y, x * y, length(x) + length(y) + length(x * y) + 2);
		x = 0; y = 0;
	}
	return 0;
}

下载了第一个数据点,自测也是对的 第一个点 in : 1 a 99 999 out: 99+999=1098 11

2020/10/15 14:24
加载中...