Pagini recente » Cod sursa (job #1295509) | Cod sursa (job #3199827) | Cod sursa (job #964698) | Cod sursa (job #1354571) | Cod sursa (job #1318831)
#include <iostream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <utility>
#include <string>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <limits>
#include <sstream>
#include <deque>
#include <bitset>
#include <complex>
#include <functional>
#include <memory>
#include <numeric>
#define x first
#define y second
typedef std::pair<int, int> pii;
using namespace std;
ifstream fin("evaluare.in");
ofstream fout("evaluare.out");
char s[100005], *p = s;
long long term();
long long merm();
long long berm();
long long fact();
long long merm()
{
long long r = berm();
while(*p == '+' || *p == '-')
{
if(*p == '+')
{
p++;
r += berm();
}
if(*p == '-')
{
p++;
r -= berm();
}
}
return r;
}
long long berm()
{
long long r = fact();
while(*p == '*' || *p == '/')
{
if(*p == '*')
{
p++;
r *= fact();
}
if(*p == '/')
{
p++;
r /= fact();
}
}
return r;
}
long long fact()
{
long long r = term();
while(*p == '^' || *p == '[')
{
if(*p == '^')
{
p++;
r = pow(r, term());
}
if(*p == '[')
{
p++;
r *= sqrt(term());
}
}
return r;
}
long long term()
{
long long r = 0;
if(*p =='(')
{
p++;
r = merm();
p++;
}
else
while(*p >= '0' && *p <= '9')
{
int x = int(*p) - 48;
r = r * 10 + x;
p++;
}
return r;
}
int main () {
/*#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif*/
fin.get(s, 100005);
fout << merm();
return 0;
}