Editorial for LOVFI

PROBLEM LINK:Contest Page | CodeChef

Practice

Author: [targer_5star]
Tester: [targer_5star]
Editorialist: [targer_5star]

DIFFICULTY:

SIMPLE

PREREQUISITES:

Array

PROBLEM:

You are Given a string SS. And you have to find whether the string contains the Characters ‘L’,‘O’,V’,‘E’. or Not.

If The string contains all four characters in any order the Print “FOUND” else print “NOT FOUND”.

QUICK EXPLANATION:

You have to just find if the occurrence of all the 4 letters i.e ‘L’,‘O’,V’,‘E’ is present or not.
and print the answer accordingly.

EXPLANATION:

We can keep 4 different Flag Variables and using a loop to traverse the whole string with 4 different conditions like if(a[i]==‘L’) and raise the flag to the “1”.

And after the loops get ended lastly we will check that all the four flags are raised or not. if all are raised then we can print “FOUND” else “NOT FOUND”.

SOLUTIONS:

Setter's Solution

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

int main() {
long long int t;
cin>>t;
while(t–)
{
string s,res=“NOT FOUND”;
cin>>s;
int a=0,b=0,c=0,d=0;
for(auto i:s)
{
if(i==‘L’)
{
a=1;
}
if(i==‘O’)
{
b=1;
}
if(i==‘V’)
{
c=1;
}
if(i==‘E’)
{
d=1;
}
if(a+b+c+d==4)
{
res=“FOUND”;
break;
}
}
cout<<res<<endl;
}
return 0;
}

Tester's Solution

//Prem se bolo Radhe Radhe
#include <bits/stdc++.h>
const long long SZ = 4e3 + 7;
const long long inf = 1e18;
const long long MOD = 1e9 + 7;
const long long mod = 1e9 + 7;
long long opnmbr = 1;
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define pll pair<ll, ll>
#define vi vector
#define vs vector
#define vpl vector
#define qi queue
#define si set
#define map map<ll, ll>
#define umap unordered_map<ll, ll>
#define fi first
#define se second
#define sz(x) (ll)x.size()
#define all© ©.begin(), ©.end()
#define allr© ©.rbegin(), ©.rend()
#define Max(a,b) ((a > b) ? a : b)
#define Min(a,b) ((a < b) ? a : b)
#define ci(X) ll X; cin>>X
#define cii(X, Y) ll X, Y; cin>>X>>Y
#define ciii(X, Y, Z) ll X, Y, Z; cin>>X>>Y>>Z
#define ciiii(W, X, Y, Z) ll W, X, Y, Z; cin>>W>>X>>Y>>Z
#define co cout<<
#define in cin>>
#define Jivan_ka_asli_aadhar_to_prem_hai_na ll ___T; cin>>___T; while (___T-- > 0)
#define Code_Wode_mai_kya_rakha_hai ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define inf 1e18
#define ed endl
#define abhi(i, n) for(ll i = 0; i < (n); i++)
#define abhi1(i, n) for(ll i = 1; i <= (n); i++)
#define abhi2(i, l, r) for(ll i = l; i < ®; i++)
#define rabhi(i, l, r) for(ll i = l; i >= ®; i–)
#define ms0(X) memset((X), 0, sizeof((X)))
#define ms1(X, V) memset((X), 1, sizeof((X)))
#define ms2(X, V) memset((X), 1, sizeof((X)))
#define flv(X, V) fill(all((X)), V)
#define gcd(a,b) __gcd(a,b)
using namespace std;
ll prmod(ll a, ll b)
{
ll ans = 1;
while (b)
{
if (b & 1) ans = (ans * a) % MOD;
b = b / 2;
a = (a * a) % MOD;
}
return ans;
}
int pri(ll n)
{
int flag=0;
for(ll i = 2; i <= n / 2; ++i)
{
if(n % i == 0)
{
flag = 1;
break;
}
}
if(flag==0)
{
return 1;
}
else
{
return 0;
}
}
ll lcm(ll a, ll b)
{
return (a / gcd(a, b)) * b;

Noob Learner, [07.07.21 16:56]
}
void Radhe_Radhe()
{
int l=0,o=0,v=0,e=0;
string s;
cin>>s;
for(ll i=0;i<s.size();i++)
{
if(s[i]==‘L’)
{
l=1;
}
if(s[i]==‘O’)
{
o=1;
}
if(s[i]==‘V’)
{
v=1;
}
if(s[i]==‘E’)
{
e=1;
}
}
if(l==1 && o==1 && v==1 && e==1)
{
cout<<“FOUND”<<"\n";
}
else
{
cout<<“Not Found”<<"\n";
}
}
int main()
{
Code_Wode_mai_kya_rakha_hai;
Jivan_ka_asli_aadhar_to_prem_hai_na
{
Radhe_Radhe();
}
}

Editorialist's Solution

#include
using namespace std;
#define ll long long int
int main()
{ int t;
cin>>t;
while(t–)
{
int l=0,o=0,v=0,e=0;
string s;
cin>>s;
for(ll i=0;i<s.size();i++)
{
if(s[i]==‘L’)
{
l=1;
}
if(s[i]==‘O’)
{
o=1;
}
if(s[i]==‘V’)
{
v=1;
}
if(s[i]==‘E’)
{
e=1;
}
}
if(l==1 && o==1 && v==1 && e==1)
{
cout<<“FOUND”<<"\n";
}
else
{
cout<<“Not Found”<<"\n";
}

}
return 0;
}

1 Like