Skip to content

Instantly share code, notes, and snippets.

@axayjha
Created December 19, 2018 06:23
Show Gist options
  • Save axayjha/fe07536d267212431d754e67a22d5914 to your computer and use it in GitHub Desktop.
Save axayjha/fe07536d267212431d754e67a22d5914 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <string>
using namespace std;
#define VOWEL 1
#define CONS 2
bool bad=false, good=false;
bool isVowel(char c)
{
if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u')
return true;
return false;
}
int count(string s, char a)
{
int count = 0;
for (int i = 0; i < s.length() ; i++)
if (s[i] == a)
count++;
return count;
}
string replace(string s, char a, char b)
{
string t = s;
for (int i = 0; i < s.length() ; i++)
if (t[i] == a) {
t[i] = b;
break;
}
return t;
}
int check_str(string s)
{
//1 - BAD
//2 - GOOD
int vow = 0, cons = 0;
for(int i = 0; i < s.length(); i++)
{
if (cons >= 3 || vow >= 5)
return 1;
if (isVowel(s[i]))
{
vow++;
cons = 0;
}
else
{
cons++;
vow=0;
}
}
if (cons >= 3 || vow >= 5)
return 1;
return 2;
}
void check(string s)
{
if (count(s, '?') == 0)
{
int res = check_str(s);
if (res == 1)
bad = true;
else if (res == 2)
good = true;
}
else{
check(replace(s, '?', 'a'));
check(replace(s, '?', 'b'));
}
}
int main(int argc, char const *argv[])
{
string s;
cin >> s;
check(s);
if (bad && good)
{
cout << "MIXED" << endl;
}
else if(bad)
{
cout << "BAD" << endl;
}
else
cout << "GOOD" << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment