1 条题解

  • 0
    @ 2025-7-5 18:20:55
    #include<bits/stdc++.h>
    using namespace std;
    int solve(){//递归求解
    	char ch;
    	int total=0;
    	int x=0;
    	while(cin>>ch){
    		if(ch=='(') total+=solve();
    		else if(ch==')') return total+x;//注意可能 x 还没加上
    		else if('0'<=ch&&ch<='9') x=x*10+ch-'0';
    		else{//'+'
    			if(x){
    				total+=x;
    				x=0;
    			}
    		}
    	}
    	return total+x;//注意可能 x 还没加上
    }
    signed main(){
    	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    	cout<<solve();
    	return 0;
    }
    
    • 1

    信息

    ID
    468
    时间
    1000ms
    内存
    256MiB
    难度
    2
    标签
    (无)
    递交数
    46
    已通过
    29
    上传者