Cod sursa(job #3302416)

Utilizator RaresHonourRares Herinean RaresHonour Data 7 iulie 2025 14:03:37
Problema Consecutive Scor 0
Compilator cpp-64 Status done
Runda Arhiva ICPC Marime 0.9 kb
#include <fstream>
#include <string>

using namespace std;

ifstream cin("emm.in");
ofstream cout("emm.out");

string s;

int expresie(string &s, int &p);
int factor(string &s, int &p);
int numar(string &s, int &p);

int expresie(string &s, int &p) {
    int rez = factor(s, p);
    while (p < s.size() && (s[p] == 'M' || s[p] == 'm')) {
        ++p;
        rez = s[p - 1] == 'M' ? max(rez, factor(s, p)) : min(rez, factor(s, p));
    }
    return rez;
}

int factor(string &s, int &p) {
    if (s[p] == '(') {
        ++p;
        int rez = expresie(s, p);
        ++p;
        return rez;
    }
    return numar(s, p);
}

int numar(string &s, int &p) {
    int n = 0;
    while (s[p] - '0' >= 0 && s[p] - '0' <= 9) {
        n = n * 10 + s[p] - '0';
        ++p;
    }
    return n;
}

int main() {
    int p = 0;
    cin >> s;
    cout << expresie(s, p);
    return 0;
}