Pagini recente »
Monitorul de evaluare
|
Cod sursă (job #817531)
Cod sursă (job
#817531)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("bizar.in");
ofstream fout("bizar.out");
string s;
stack<int> stiva; ///-1 pt (
int main()
{
getline(fin, s);
int lung = s.size();
for(int i=0; i<lung; i++) {
if(s[i] == ' ' || s[i] == ',');
else if(s[i] == '(') stiva.push(-1);
else if(isdigit(s[i])) {
int x = 0;
while(isdigit(s[i])) x = 10 * x + s[i++] - '0';
i--, stiva.push(x);
}
else {
///e )
vector<int> v;
while(stiva.top() != -1) v.push_back(stiva.top()), stiva.pop();
reverse(v.begin(), v.end());
stiva.pop(); ///scoatem (
int cnt = stiva.top(); stiva.pop();
int n = v.size();
if(cnt % n == 0) cnt = n;
else cnt %= n;
stiva.push(v[cnt - 1]);
}
///stack<int> aux = stiva;
///while(!aux.empty()) cout << aux.top() << " ", aux.pop();
///cout << '\n';
}
fout << stiva.top();
return 0;
}