求助全部WA
查看原帖
求助全部WA
472208
Renader楼主2021/2/17 23:51

测试可以过,第一个也可以过,第一个WA说第一行过短

#include <bits/stdc++.h>
using namespace std;

int string_to_int(string x){
	stringstream y;
	y << x;
	int z;
	y >> z;
	return z;
}

string int_to_string(int x){
	stringstream y;
	y << x;
	return y.str();
}
string r[55];
int r1[55];
int n;
int s = 0;
char type, memo;
string x, y;
string z;
bool flag = true;
int main()
{
	cin >> n;
	int count = 0;
	for(int i = 0; i < n; i++){
		fflush(stdin);
		if(flag){
			type = getchar();
			if(type == 'a' || type == 'b' || type == 'c'){
				memo = type;
			}
		}
		
		switch(memo){
			case 'a':
				cin >> x >> y;
				if(type != 'a'){
					flag = true;
					x = type + x;
				}
				z = int_to_string(string_to_int(x)+string_to_int(y));
				count += x.length()+y.length()+z.length()+2;
				r[s] = x+"+"+y+"="+z;
				r1[s++] = count;
				count = 0;
				break;
			case 'b':
				cin >> x >> y;
				if(type != 'b'){
					flag = true;
					x = type + x;;
				}
				z = int_to_string(string_to_int(x)-string_to_int(y));
				count += x.length()+y.length()+z.length()+2;
				r[s] = x+"-"+y+"="+z;
				r1[s++] = count;
				count = 0;
				break;
			case 'c':
				cin >> x >> y;
				if(type != 'c'){
					flag = true;
					x = type + x;
				}
				z = int_to_string(string_to_int(x)*string_to_int(y));
				count += x.length()+y.length()+z.length()+2;
				r[s] = x+"*"+y+"="+z;
				r1[s++] = count;
				count = 0;
				break;
		}
	}
	for(int i = 0; i < s; i++){
		cout << r[i] << endl << r1[i] << endl;
	}
	
	return 0;
}
2021/2/17 23:51
加载中...