3 条题解

  • 1
    @ 2025-11-6 20:13:54
    #include<bits/stdc++.h>
    #define ll long long
    #pragma GCC optimize(2)
    #define un unsigned
    #define int long long
    #define db double
    #define st string
    #define ct const
    #define xh(a,b,c) for(int a=b;a<=c;a++)
    #define wx while(1)
    #define dn(a,b,c) for(int a=b;a>=c;a--)
    using namespace std;
    string s;
    int ans,l;
    bool f[1010];
    signed main(){
    	cin>>s;
    	s+=')';
    	l=s.size();
    	
    	xh(i,0,l-1){
    		if(s[i]=='+'||s[i]=='('||s[i]==')'||f[i])continue;
    		int sum=0;
    		xh(j,i,l-1){
    			if(s[j]=='+'||s[j]=='('||s[j]==')')break;
    			f[j]=1;
    			sum=sum*10+s[j]-'0';
    		}
    		ans+=sum;
    	}
    	cout<<ans;
    	return 0;
    }
    
    
    • 0
      @ 2025-11-6 20:14:45

      `` #include<bits/stdc++.h> #define ll long long #pragma GCC optimize(2) #define un unsigned #define int long long #define db double #define st string #define ct const #define xh(a,b,c) for(int a=b;a<=c;a++) #define wx while(1) #define dn(a,b,c) for(int a=b;a>=c;a--) using namespace std; string s; int ans,l; bool f[1010]; signed main(){ cin>>s; s+=')'; l=s.size();

      xh(i,0,l-1){
      	if(s[i]=='+'||s[i]=='('||s[i]==')'||f[i])continue;
      	int sum=0;
      	xh(j,i,l-1){
      		if(s[j]=='+'||s[j]=='('||s[j]==')')break;
      		f[j]=1;
      		sum=sum*10+s[j]-'0';
      	}
      	ans+=sum;
      }
      cout<<ans;
      return 0;
      

      }

      ``

      • -2
        @ 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
        难度
        3
        标签
        (无)
        递交数
        55
        已通过
        32
        上传者