1. 程式人生 > >3515 翻譯布林表示式

3515 翻譯布林表示式

#include<bits/stdc++.h>
using namespace std;
string s;
int t,f;
vector<string>ans;
int main()
{
    int n;
    scanf("%d\n",&n);
    while(n--)
    {
       getline(cin,s);
        t=1,f=0;
        s += " end";
        string x;
        stringstream ss(s);
        int id=100;
        while
(ss>>x) { if(x == "or") { printf("%d(j%s,%s,%s,%d)\n",id,ans[1].c_str(),ans[0].c_str(),ans[2].c_str(),t); t=id++; printf("%d(j,_,_,%d)\n",id,id+1); id++; ans.clear(); } else
if(x == "end") { printf("%d(j%s,%s,%s,%d)\n",id++,ans[1].c_str(),ans[0].c_str(),ans[2].c_str(),t); /* t=id++*/; printf("%d(j,_,_,%d)\n",id++,f); /* id++;*/ ans.clear(); } else if(x == "and"
) { printf("%d(j%s,%s,%s,%d)\n",id,ans[1].c_str(),ans[0].c_str(),ans[2].c_str(),id+2); id++; printf("%d(j,_,_,%d)\n",id,f); f=id++; ans.clear(); } else ans.push_back(x); } } return 0; }