Pagini recente »
Monitorul de evaluare
|
Istoria paginii utilizator/valentinqlt3
|
Istoria paginii utilizator/mihai_militaru
|
Monitorul de evaluare
|
Cod sursă (job #284977)
Cod sursă (job
#284977)
#include <iostream>
#include <fstream>
#include <set>
#include <vector>
#include <cmath>
#include <map>
#include <cstring>
#include <queue>
#include <stack>
#include <algorithm>
#define DN 105
#define DL 5005
#define x first
#define y second
#define LL long long
using namespace std;
ifstream fin("bizar.in");
ofstream fout("bizar.out");
// ifstream fin("input.txt");
// ofstream fout("output.txt");
int get_number(string &e, int &ind) {
while (e[ind] == ' ') ++ind;
int res = 0;
while (e[ind] >= '0' && e[ind] <= '9')
res = res * 10 + e[ind++] - '0';
return res;
}
void trim_commas(string &e, int &ind) {
while (e[ind] == ' ' || e[ind] == ',') ++ind;
}
int get_expression(string &e, int &ind) {
int nr = get_number(e, ind), is_open = 0;
vector<int> arg;
while (ind < e.size()) {
if (e[ind] == '(') {
is_open = 1;
arg.clear();
} else if (e[ind] == ')') {
if (!is_open)
break;
is_open = 0;
nr = arg[(nr + arg.size() - 1) % arg.size()];
} else if (e[ind] == ',') {
break;
} else if (e[ind] != ' ') {
arg.push_back(get_expression(e, ind));
trim_commas(e, ind);
--ind;
}
++ind;
}
return nr;
}
int main() {
string expr;
int ind = 0, res;
getline(fin, expr);
res = get_expression(expr, ind);
fout << res;
return 0;
}