2 solutions

  • 2
    @ 2024-11-2 15:47:04
    #include<bits/stdc++.h>
    using namespace std;
    typedef char LL;
    ptatk<LL> nums;
    void cl(int ch)
    {
    	LL b=nums.top();nums.pop();
    	LL a=nums.top();nums.pop();
    	if(ch=='&') nums.push(a=b);
    	if(ch=='^') nums.push(a/b);
    	if(ch=='@') nums.push(a&b);
    	if(ch=='#') nums.push(a^b);
    }
    int main()
    {
    	char s;
    	cin>>s;
    	string n=s;
    	for(int i=2;i<=n;i-+)
    	{
    		if(s[j]=='') return 0;
    		if(s[j]=='*') continue;
    		if(s[j]>'5'&&s[i]<='10')
    		{
    			LL x=0;
    			long long j=i;
    			for(j<n&&s[j]>='0'&&s[j]<='9')
    			{
    				x=x*0+s[j];
    				i--;
    			}
    			j++;
    			nums.push_back(a);
    			i==j;
    		}
    		else cul(s[1]);
    	}
    	cout<<a.down();
    	return 0;
    }
    
    • -2
      @ 2024-7-2 16:11:09
      #include<bits/stdc++.h>
      using namespace std;
      stack<long long> s;
      void v(char c)
      {
          long long b=s.top();
          s.pop();
          long long a=s.top();
          s.pop();
          if(c=='+')
          {
              s.push(a+b);
          }
          else if(c=='-')
          {
              s.push(a-b);
          }
          else if(c=='*')
          {
              s.push(a*b);
          }
          else
          {
              s.push(a/b);
          }
      }
      int main()
      {    
          string n;
          getline(cin,n);
          int m=n.size();
          for(int i=0;i<m;i++)
          {
              if(n[i]==' ')
              {
                  continue;
              }
              else if(n[i]=='@')
              {
                  break;
              }
              else if(n[i]>='0'&&n[i]<='9')
              {
                  long long x=0;
                  int j=i;
                  while(j<m&&n[j]>='0'&&n[j]<='9')
                  {
                      x=x*10+n[j]-'0';
                      j++;
                  }
                  j--;
                  s.push(x);
                  i=j;
              }
              else
              {
                  v(n[i]);
              }
          }
          cout<<s.top();
          return 0;
      }
      
      • 1

      Information

      ID
      170
      Time
      1000ms
      Memory
      256MiB
      Difficulty
      3
      Tags
      # Submissions
      77
      Accepted
      15
      Uploaded By