Cod sursa(job #1827688)

Utilizator pibogaBogdan piboga Data 12 decembrie 2016 09:21:28
Problema Bool Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.52 kb
#include <fstream>
#include <cstring>

using namespace std;

ifstream fin ("evaluare.in");
ofstream fout("evaluare.out");

char c[1010],a[1010],k,d[1010];
int b[1010],vl[260];
int x,y,i,n;
bool ok;

void tr()
{
    int m;int n;
    m=b[y-1]; n=b[y];
    --y;
    switch (a[x])
    {
        case '+' : { b[y]=m+n ; break; }
        case '-' : { b[y]=m-n ; break; }
        case '*' : { b[y]=m*n ; break; }
        case '/' : { b[y]=m/n ; break; }
    }
    --x;

}

void dcd()
{
    ++i;
    if (c[i]==' ')
    {
        --i;
        b[++y]=vl[c[i]];
    }

    if (c[i]=='N') a[++x]='&';

    else if(c[i]=='R')
        a[++x]='|';

    else if (c[i]=='O')
        a[++x]='!';

    else
    {

    }
}


int main()
{
    fin.getline (c+1,1010);
    n=strlen(c+1);

    vl['!']=1;vl['&']=2;vl['|']=3;

    fin>>p; fin.getline(d+1,1010);

    c[0]='('; c[n+1]=')';

    for (j=1;j<=p;++j)
    {
        vl[d[j]]=!v[d[j]];

        for (i=0;i<=n+1;++i)
        {
            if (c[i]=='(')
            {
                a[++x]='(';
            }
            else if (c[i])==')';
            {
                while (a[x]!='(')
                {
                    tr();
                }
            }
            else if (c[i]==' ')
            {
                ++i;
            }
            else
            {
                dcd();

            }

            else
            {

            }



        }
    }

    fout << b[1];

    return 0;
}