本地测试通过,提交全部WA。求大佬求解!!!
查看原帖
本地测试通过,提交全部WA。求大佬求解!!!
728949
lucas_777楼主2023/1/27 19:34
#include <iostream>
#include <string>
#include <cstring>
using namespace std;

int main(){

	int i, n1, n2;
	cin >> i;
	char op;
	for(int x = 0; x <= i; ++x) {
		string s;
		getline(cin, s);
		
		if(s.size() != 0) {
			char tmp = s.front();
			if(tmp == 'a' || tmp == 'b' || tmp == 'c') {
				op = tmp;
				s = s.substr(2);
			}
			sscanf(s.data(), "%d%d", &n1, &n2);
			string ops;
			int result;
			switch(op) {
				case 'a' :
					ops = "+";
					result = n1 + n2;
					break;
					
				case 'b' :
				 	ops = "-";
					result = n1 - n2;
				 	break;
				 	
				case 'c' :
				 	ops = "*";
					result = n1 * n2;
				 	break;
			}
			string xx = to_string(n1) + ops + to_string(n2) + "=" + to_string(result);
			
			cout << xx << endl;
			cout << xx.length() << endl;
		}
	}
	return 0;	
}
2023/1/27 19:34
加载中...