Pagini recente » Cod sursa (job #1686972) | Cod sursa (job #1220879) | Cod sursa (job #1395384) | Cod sursa (job #2671453) | Cod sursa (job #2153145)
#include <fstream>
#include <string>
#include <list>
#include <algorithm>
#include <iostream>
std::ifstream f("evaluare.in");
std::ofstream g("evaluare.out");
using namespace std;
string sir;
int p[100100];
struct nod
{
char* val;
nod* stanga;
nod* dreapta;
};
bool inf(int i,int j)
{
for(int z=i; z<=j; z++)
if(p[z] < 1<<25)
return true;
return false;
}
void arbore(int x,int y, nod* A)
{
if(y-x>1 and inf(x,y))
{
int* m;
m=min_element(p+x,p+y);
int i=x;
while(p[i]!=*m)
i++;
char temp[3];
temp[0]=sir[i];
temp[1]='\0';
nod* J; nod* Q;
A->val=temp;
A->dreapta='\0';
A->stanga='\0';
// arbore(x,i-1,A->stanga);
//arbore(i+1,y,A->dreapta);
//A->stanga=J;
// A->dreapta=Q;
}
else
{
if(y-x>1)
{
char yey[100100];
int z=0;
for(int k=x; k<=y; k++)
yey[z++]=sir[k];
yey[z]='\0';
//nod* o;
//o=new nod;
A->val=yey;
A->dreapta='\0';
A->stanga='\0';
//return o;
}
else
{
if(p[x]==1<<25)
{
// nod* o;
//o=new nod;
char temp[6];
temp[0]=sir[x];
temp[1]='\0';
A->val=temp;
A->dreapta='\0';
A->stanga='\0';
//return o;
}
else
{
//nod* o;
//o=new nod;
char temp[6];
temp[0]=sir[x];
temp[1]='\0';
A->val=temp;
A->dreapta='\0';
A->stanga='\0';
//return o;
}
}
}
}
int main()
{
f>>sir;
int b=0;
for(int i=0; i<sir.length(); i++)
{
if(sir[i]=='+' or sir[i]=='-')
{
p[i]=1+b;
}
else if(sir[i]=='*' or sir[i]=='/')
{
p[i]=10+b;
}
else if(sir[i]=='(')
{
b+=10;
p[i]=1<<25;
}
else if(sir[i]==')')
{
b-=10;
p[i]=1<<25;
}
else
p[i]=1<<25;
}
for(int i=0; i<sir.size(); i++)
g<<p[i]<<' ';
g<<'\n';
int *u;
u=min_element(p,p+sir.length());
int j=0;
while(p[j]!=*u)
j++;
g<<*u<<' '<<j;
nod* A;
A=new nod;
A->dreapta='\0';
A->stanga='\0';
nod* B;
B=A;
nod* C;
arbore(0,sir.size(),A);
while(B)
{
cout<<B->val<<' ';
B=B->dreapta;
}
return 0;
}