Something strange I can't debug

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.

format your code

3 Likes

Sory for the problem. Did it. Please help.

first parameter in str.substr should be the starting index of substring and not the character.

1 Like