Ques: Find if there is a string in the array preceding with ’ ! ’ and another with non ’ ! ’ and then print it.
Example :
xyz
!xyz
Output
xyz
int n;
cin>>n;
unordered_set<string> s;
vector<string> vs(n);
bool flag = true;
for(int i = 0; i < n; i++){
cin>>vs[i];
string str = vs[i];
if( str[0] == '!'){
if(s.count(str.substr(str[1],sz(str))) != 0){
flag = false;
cout<<str.substr(str[1],sz(str));
break;
}
s.insert(str);
}
else{
string st = "!" + str;
if( s.count(st) != 0 ){
cout<<str;
flag = false;
break;
}
else s.insert(str);
}
}
if(flag)
cout<<"satisfiable"<<endl;
Am getting finished with code 3 in sublime text editor 3 and no output can understand why.