UVa 11357 - Ensuring Truth Solution

#include <iostream>
#include <string>
#include <set>
using namespace std;
int main(){
    int t;
    cin>>t;
    while(t--){
        string s;
        cin>>s;
        int i=1;
        int fl=0;
        while(i<s.size()){
            if(s[i]=='|')
                break;
            while(i<s.size()&&(s[i]=='('||s[i]==')'))
                i++;
            set<char> a;
            if(i==s.size())
                break;
            int flag=1;
            while(i<s.size()&&s[i]!=')'){
                if(s[i]=='&')
                    i++;
                if(s[i]=='~'){
                    if(a.find(s[i+1])!=a.end())
                        flag=0;
                    else
                        a.insert(s[i+1]-'a'+'A');
                    i++;
                }
                else{
                    if(a.find(s[i]-'a'+'A')!=a.end())
                        flag=0;
                    else
                        a.insert(s[i]);
                }
                i++;
            }
            fl|=flag;
        }
        if(fl)
            cout<<"YES"<<endl;
        else
            cout<<"NO"<<endl;
    }
}

Comments