明明答案完全一样但全WA!(cpp)
查看原帖
明明答案完全一样但全WA!(cpp)
372656
LuLingchenC_Code楼主2022/8/22 15:23
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

const int MAXN = 6e4 + 10;
string s, t, s_a, s_b;
char c;
int q, num = 0, a, b;

int string_int(string st) {
    int index = 0, res = 0;
    while(index < st.length() ) {
        res = res*10 + (st[index]-'0');
        index++;
    }
    return res;
}

void check(string st, int &a, int &b) {
    int idx = 1;
    while(st[idx] != ' ') {
        idx++;
    }
    // printf("idx:%d\n", idx);
    s_a = st.substr(0, idx), s_b = st.substr(idx+1);
    // cout << s_a << "#" << s_b << endl;
    a = string_int(s_a);
    b = string_int(s_b);
}

void Plus(int a, int b) {
    num = printf("%d+%d=%d\n", a, b, a+b);
    // printf("%d\n", num-1);
}

void Minus(int a, int b) {
	num = printf("%d-%d=%d\n", a, b, a-b);
	// printf("%d\n", num-1);
}

void Multiple(int a, int b) {
	num = printf("%d*%d=%lld\n", a, b, a*b);
	// printf("%d\n", num-1);
}

int main() {
	scanf("%d ", &q);
	while(q--) {
		getline(cin, s);
		// printf("q:%d ", q);
		// cout << s.substr(2) << endl;
		if('a' <= s[0] && s[0] <= 'c') {
		    check(s.substr(2), a, b);
		    c = s[0];
		}else{
		    check(s, a, b);
		}
		switch(c) {
			case 'a':Plus(a, b);break;
			case 'b':Minus(a, b);break;
			case 'c':Multiple(a, b);break;
		}
	    printf("%d\n", num-1);
	}
	return 0;
}
2022/8/22 15:23
加载中...