New Ket Practice Game 15 Jim's op-

Source: Internet
Author: User
Tags time limit
Time limit: C/s 1 sec, other languages 2 seconds
Space limitations: C/C + + 262144K, other languages 524288K
64bit IO Format:%lld
Title DescriptionWhen Jim brushes the cattle to practice game B. Maze, in order to record the two-dimensional maze, each step can walk in the four direction of displacement, write the code contains the following paragraphs:
int offset[4][2] = {(1, 0), (0, 1), (-1, 0), (0,-1)};
Sharp-eyed readers should quickly find out what's wrong with this code. XD Correct wording should be as follows:
int offset[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0,-1}};
Jim accidentally punched the curly brace into parentheses so the actual four displacement is recorded as: (0,1), (0,-1), (0,0), (0,0) After this experience, Jim knew that the original comma (comma) is a C + + operator (operator).
Jim began to wonder, to give you a number, parentheses, commas, a valid formula, can quickly get the result of this calculation. Please help Jim write a procedure for calculating this kind of calculation. 〜note: People unfamiliar with the comma operator can refer to cppreference.com.
The following also gives a simple definition of the comma operator: (If you are not careful with C + + regulations, please take the following four): 1. For all integers that satisfy-2 31≤x≤2 31-1, x itself is a valid expression, and the value of this expression is that number. (if x is not 0, the number part cannot start with 0, if 0, it must just be a 0.)
2. If e 1,e 2,...,e n is a valid expression, then E 1,e 2,...,e n is also a valid expression, and its value is the value of e N.
3. If e is a valid expression, then (e) is also a valid expression with the value of E.
It is illegal to use an expression that is not available in the relationship of the above-quoted items.
For example, 514,1,2, ( -2147483648,2,4), (((0)), (1), (2) are all valid expressions in this question, but 0514,-02, (), (23,43)) are illegal.

Input Description:
Enter only one row, containing a string E, which is a legal expression consisting of only the left and right parentheses ' (', ') ', comma ', ', and Integer.
Output Description:
The output line contains an integer that represents the result of the operation of the input supplied expression.
Example 1 input
(5,-14)
Output
-14
Example 2 input
((406, (0,2147483647,-2147483648)))
Output
-2147483648
remark:
the range of all integers in 1≤|e|≤100 e is -231≤x≤231-1
e satisfies the legal expression referred to in note, with special emphasis, E does not contain "(space)
#include <bits/stdc++.h>
using namespace std;
int main () {
    string s;
    cin>>s;
    int len=s.length ();
    if (len<=2) {for
        (int i=0;i<len;i++) cout<<s[i];
        cout<<endl;
        
    }
    else{
    int vis=0;
    for (int i=len-1;i>=0;i--) {
        if (s[i]== ', ') {
            vis=i;break;
        }
    }
        
       
    Vector<char> ans;
    for (int i=vis;i<len;i++) {
        if (s[i]>= ' 0 ' &&s[i]<= ' 9 ' | | s[i]== '-') Ans.push_back (S[i]);
        
    }
    
    for (int i=0;i<ans.size (); i++) {
        cout<<ans[i];
    }
    cout<<endl;
    }
}

The comma operation is actually based on the result of the symbolic priority, so as long as the number of the last assignment is found is the result.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.