String and characters - Editorial

PROBLEM LINK:

Practice
Div-2 Contest

Author: Setter’s name
Tester: Tester’s name
Editorialist: Editorialist’s name

DIFFICULTY:

EASY.

PREREQUISITES:

PROBLEM:

Your are given a string S containing only lowercase letter and a array of character arr. You have to check whether the string contains characters from that array only.

EXPLANATION:

You have first know which elements you have in your character array. Then traverse the string and check whether the each element of string is present in given character array or not.
There are multiple ways to do this. We are using maps here.

SOLUTIONS:

#include<bits/stdc++.h>
using namespace std;

int solve(){
	string str;
	cin >> str;
	int n;
	cin >> n;
	char arr[n];
	map<char, int> mp;
	for (int i = 0; i < n; i++)
	{
    	cin >> arr[i];
    	mp[arr[i]]++;
	}

	bool go = false;
	for (int i = 0; i < str.length(); i++)
	{
    	if (mp[str[i]] < 1)
    	{
       		go = true;
    	}
	}
	if (go)
	{
    	return 0;
	}
	else
	{
    	return 1;
	}
}

int main(){
	int testcase;	
	cin>>testcase;

	while(testcase--){
		cout<<solve()<<endl;	
	}
}