#2330540

Solution for 2570: Shipura by noy72

Source Code Status Test Cases
    Policy: public     Reviewed: 50    
00.04 sec    4860 KB    70 lines     1685 bytes    2017-05-22 11:01
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).*begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
using namespace std;

const int M = 1000000007;

string s;

typedef string::const_iterator State;
int number(State&);
int term(State&);
int expression(State&);


// ??°??????????????????????????????????????°????????????
int number(State &begin) {
    int ret = 0;

    while (isdigit(*begin)) {
        ret *= 10;
        ret += *begin - '0';
        begin++;
    }

    return ret;
}


// ?????????????????????????????????????????????????????????????????????
int term(State &begin) {
    if (*begin == 'S') {
        begin++; begin++;
        long long ret = expression(begin);
        begin++;
        return ret * ret % M;
    } else {
        return number(begin);
    }
}

// ?????????????????????????????????????????????????????????????????????
int expression(State &begin) {
    int ret = term(begin);

    while(s.end() - begin >= 2){
        if (*begin ==  '>' && *(begin + 1) == '>' && *(begin + 2) != '>'){
            begin++; begin++;
            ret = ret >> min(term(begin), 31);
        } else {
            break;
        }
    }

    return ret;
}

int main(){
    string tmp;
    while(getline(cin,tmp),tmp != "#"){
        s="";
        for(auto it:tmp) if(it != ' ') s+=it;
        State state = s.begin();
        cout << expression(state) << endl;
    }
}


Compile Error Logs:
You are not authorized to see the message.

Status
Judge: 1/1 C++11 CPU: 00.04 sec Memory: 4860 KB Length: 1685 B 2017-05-22 11:01 2017-05-22 11:01
Results for testcases
Case # Verdict CPU Time Memory In Out Case Name
Case #1: : Accepted 00.04 sec 4860 KB
< prev | / | next >  
 
Judge Input #  ( | ) Judge Output #  ( | )


Comments
 
 Under Construction.
 
Categories
 
 
Free Tags