InterviewRound1(https://www.codechef.com/SMCC2021/problems/CODE004)

Practice

Author: Sachin Singh
Tester: Sachin Singh
Editorialist: Sachin Singh

DIFFICULTY:

CAKEWALK, SIMPLE, EASY.

PREREQUISITES:

String .

PROBLEM:

CodeMaster went for a interview.Interviewer told him, you have to given a string. You have to find that whether the string contains word CoDe or not.

But there is a twist. Twist is that….

  1. In given string at least two E must be present. one is in lowercase letter(i.e e) and another one is in uppercase letter(i.e E) (Except for the first and last index of string).

If CodeMaster is able to find the word CoDe then print SELECTED else print REJECTED.

QUICK EXPLANATION:

Consider You have to given an string and you have to find word CoDe. But condition is given that there must be two (E) present one in upper case letter(i.e. E) and one in lower case(i.e. e) .One more condition is given that is (expect first and last index of string) which means if E/e present either first or last index may not consider for finding the word CoDe.
In simple way we can say that at least one E and one e must be present in the string expect first and last index of string.

EXPLANATION:

we will try to understand problem by using an example.
Let’s consider an string EeCoDEe. we have to find word CoDe. Consider indexing starts from zero.
At 2nd index of string is ‘C’, third index ‘o’,fourth index ‘D’ and first index ‘e’ and also present two ‘E’. One is in lower case letter at first index and one in an upper case letter at fifth index. so it full fill our condition that’s its output is SELECTED.

SOLUTIONS:

Setter's Solution

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

int main()
{
int t;
cin>>t;
while(t–)
{
string s;
cin>>s;
int k=s.length();
int cnt=0,cnt1=0,cnt2=0,cnt3=0,cnt4=0;
for(int i=0;i<k;i++)
{
if(i==0 && (s[i]==‘E’||s[i]==‘e’))
{
continue;
}
else if(i==(k-1)&&(s[i]==‘E’||s[i]==‘e’))
{
continue;
}
else if(s[i]==‘C’)
{
cnt=1;
}
else if(s[i]==‘D’)
{
cnt2=1;
}
else if(s[i]==‘o’)
{
cnt1=1;
}
else if(s[i]==‘e’)
{
cnt3=1;
}
else if(s[i]==‘E’)
{
cnt4=1;
}

    }
    if(cnt==1&&cnt2==1&&cnt3==1&&cnt1==1&&cnt4==1)
    {
        cout<<"SELECTED"<<endl;
    }
    else
    {
        cout<<"REJECTED"<<endl;

    }



}

}

Tester's Solution

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

int main()
{
int t;
cin>>t;
while(t–)
{
string s;
cin>>s;
int k=s.length();
int cnt=0,cnt1=0,cnt2=0,cnt3=0,cnt4=0;
for(int i=0;i<k;i++)
{
if(i==0 && (s[i]==‘E’||s[i]==‘e’))
{
continue;
}
else if(i==(k-1)&&(s[i]==‘E’||s[i]==‘e’))
{
continue;
}
else if(s[i]==‘C’)
{
cnt=1;
}
else if(s[i]==‘D’)
{
cnt2=1;
}
else if(s[i]==‘o’)
{
cnt1=1;
}
else if(s[i]==‘e’)
{
cnt3=1;
}
else if(s[i]==‘E’)
{
cnt4=1;
}

    }
    if(cnt==1&&cnt2==1&&cnt3==1&&cnt1==1&&cnt4==1)
    {
        cout<<"SELECTED"<<endl;
    }
    else
    {
        cout<<"REJECTED"<<endl;

    }



}

}

Editorialist's Solution

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

int main()
{
int t;
cin>>t;
while(t–)
{
string s;
cin>>s;
int k=s.length();
int cnt=0,cnt1=0,cnt2=0,cnt3=0,cnt4=0;
for(int i=0;i<k;i++)
{
if(i==0 && (s[i]==‘E’||s[i]==‘e’))
{
continue;
}
else if(i==(k-1)&&(s[i]==‘E’||s[i]==‘e’))
{
continue;
}
else if(s[i]==‘C’)
{
cnt=1;
}
else if(s[i]==‘D’)
{
cnt2=1;
}
else if(s[i]==‘o’)
{
cnt1=1;
}
else if(s[i]==‘e’)
{
cnt3=1;
}
else if(s[i]==‘E’)
{
cnt4=1;
}

    }
    if(cnt==1&&cnt2==1&&cnt3==1&&cnt1==1&&cnt4==1)
    {
        cout<<"SELECTED"<<endl;
    }
    else
    {
        cout<<"REJECTED"<<endl;

    }



}

}