蒟蒻求debug
  • 板块题目总版
  • 楼主Linktux
  • 当前回复1
  • 已保存回复2
  • 发布时间2023/11/19 13:48
  • 上次更新2023/11/19 15:52:12
查看原帖
蒟蒻求debug
1185284
Linktux楼主2023/11/19 13:48

P1689 方程求解

9WA1AC,请大佬调试
#include <bits/stdc++.h>
using namespace std;
int main(){
    int part=1,x=0,y=0,z=0;
    string s;
    bool flag=true;
    const int mark=0x3f3f3f;
    getline(cin,s);
    for(int i=0;i<s.length();i++){
        if(s[i]==' ')continue;
        if(isdigit(s[i])){
            switch(part){
                case 1:x=x*10+(s[i]-'0');
                case 2:y=y*10+(s[i]-'0');
                case 3:z=z*10+(s[i]-'0');
            }
        }
        switch(s[i]){
            case '+':part=2;break;
            case '-':part=2,flag=false;break;
            case '=':part=3;break;
            case '?':
                if(part==1)x=mark;
                if(part==2)y=mark;
                if(part==3)z=mark;
                break;
        }
    }
    if(flag){
        if(x==mark)cout<<z-y<<endl;
        else if(y==mark)cout<<z-x<<endl;
        else cout<<x+y<<endl;
    }else{
        if(x==mark)cout<<y+z<<endl;
        else if(y==mark)cout<<x-z;
        else cout<<x-y<<endl;
    }
    return 0;
}
2023/11/19 13:48
加载中...