求助!!!
查看原帖
求助!!!
519573
Daniel_yao楼主2022/7/8 14:24
#include <bits/stdc++.h>
using namespace std;
const int N = 4;
char s, f[N], h;
int tot;
int main(){
  while(cin >> s){
    if((s >= '0' && s <= '9') || s == '?'){
      f[++tot] = s;
    }
    if(s == '+') h = '+';
    else if(s == '-')h = '-';
  }
  if(h == '+'){
    if(f[3] == '?') cout << (f[1] - '0' + f[2] - '0') << endl;
    if(f[2] == '?') cout << (f[3] - f[1]) << endl;
    if(f[1] == '?') cout << (f[3] - f[2]) << endl;
  } else if (h == '-'){
    if(f[3] == '?') cout << (f[1] - f[2]) << endl;
    if(f[2] == '?') cout << (f[1] - f[3]) << endl;
    if(f[1] == '?') cout << (f[3] - '0' + f[2] - '0') << endl;
  }
  return 0;
}

2022/7/8 14:24
加载中...