Editorial - Cheems Language

PROBLEM LINK:]

Practice

Setters/Editorialist: Pradeep Kumar Sahu
Tester: Pratyaksh Gupta

DIFFICULTY:

CAKEWALK

PREREQUISITES:

String

PROBLEM:

Chef and Cheems are best friends. Chef lives in Chefland and Cheems lives on Doge Island. Chef is planning a trip to Doge Island, so he has to learn Cheems language.

The string is in Cheems language if it contains at least one M or m.

Help Chef in identify if the given string is in Cheems language or not.

EXPLANATION:

Check all the character of the string, if string contain M or m character then print "YES" otherwise "NO".

SOLUTIONS:

Setter's Solution
#include <bits/stdc++.h>
using namespace std;

bool solve(string s , int n)
{
    for(int i=0 ; i<n; i++)
    {
        if(s[i] == 'm' || s[i] == 'M')
        return true;
    }
    return false;
}

int main() {
    int t;
    cin >> t;
    while(t--)
    {
        int n;
        cin >> n;
        string s ;
        cin >> s;

        if(solve(s , n))
        cout << "YES\n";
        else
        cout << "NO\n";
    }
	
	return 0;
}
Tester's Solution
#include <bits/stdc++.h>
using namespace std;

void solve(){
    int n;
    cin>>n;
    assert(n>=1&&n<=1000);
    string s;
    cin>>s;
    assert(s.size()==n);
    for(auto i:s){
        if(i=='M'||i=='m'){
            cout<<"YES\n";
            return;
        }
    }
    cout<<"NO\n";
}

int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	// your code goes here
	int test;
	cin>>test;
	assert(test>=1&&test<=100);
	while(test--)
	    solve();
	return 0;
}