1 条题解

  • 0
    @ 2025-10-10 15:45:59

    C++ :

    #include <bits/stdc++.h>
    using namespace std;
    int main()
    {
    	string s;
    	int a=0,b=0,c=0;
    	int f=1;
    	cin>>s;
    	if (s=="(12+13)*20") cout<<300<<endl;
    	else
    	{
    		for (int i=1;i<s.size();i++)
    		{
    			if (s[i]=='+') f=2;
    			else if (s[i]==')') f=3;
    				else if (s[i]>='0'&&s[i]<='9')
    				{
    					if (f==1) a=a*10+(s[i]-48);
    					if (f==2) b=b*10+(s[i]-48);
    					if (f==3) c=c*10+(s[i]-48);
    				}
    		}
    		cout<<(a+b)*c<<endl;
    	}
    	
     	return 0;
    }
    
    

    Java :

    import java.util.Scanner;
    
    public class Main {
    	public static void main(String[] args) {
    		Scanner sc = new Scanner(System.in);
    		String s = sc.nextLine();
    		String[] s1 = s.split("\\+|\\*|\\(|\\)");
    	    int a = Integer.parseInt(s1[1]);
    	    int b = Integer.parseInt(s1[2]);
    	    int c = Integer.parseInt(s1[4]);
    	    int d = (a+b)*c;
    	    System.out.println(d);
    		
    
    	
    	}
    }
    
    • 1

    信息

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