Header Ad

HackerEarth All Vowels problem solution

In this HackerEarth All Vowels problem solution Vowels are very essential characters to form any meaningful word in the English dictionary. There are 5 vowels in the English language - a, e, i, o u. You are given a random string containing only lowercase letters and you need to find if the string contains ALL the vowels.


HackerEarth All Vowels problem solution


HackerEarth All Vowels problem solution.

#include <bits/stdc++.h>

#define rep(i,n) for(i=0;i<n;i++)
#define ll long long
#define elif else if
#define pii pair< int, int>
#define mp make_pair
#define pb push_back
using namespace std;
#define gc getchar_unlocked

int randi(int l,int r)
{
if(r<l)
return l;
return rand()%(r-l+1) +l;
}

int done[5]={0};
int main()
{
freopen("in.txt","r",stdin);
freopen("out","w",stdout);
int i,j,n,mi=99999,ma=0;
cin>>n;
string st;
cin>>st;
rep(i,n)
{
if(st[i]=='a')
done[0]++;
if(st[i]=='e')
done[1]++;
if(st[i]=='i')
done[2]++;
if(st[i]=='o')
done[3]++;
if(st[i]=='u')
done[4]++;
}
rep(i,5)
{
if(!done[i])
{
cout<<"NO";
return 0;
}
}
cout<<"YES";
return 0;
}

Second solution

#include<bits/stdc++.h>
using namespace std;
int main(){

int N;
string S;
cin>>N>>S;
assert(N>=1 && N<=10000);
assert(S.length()==N);
// a,e,i,o,u
bool flag1=false,flag2=false,flag3=false,flag4=false,flag5=false;
for(int i=0;i<N;i++){
if(S[i]=='a')
flag1=true;
else if(S[i]=='e')
flag2=true;
else if(S[i]=='i')
flag3=true;
else if(S[i]=='o')
flag4=true;
else if(S[i]=='u')
flag5=true;

if(flag1==true && flag2==true &&flag3==true && flag4==true && flag5==true)
break;
}

if(flag1==true && flag2==true &&flag3==true && flag4==true && flag5==true)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;

}


Post a Comment

0 Comments