Skip to content

Instantly share code, notes, and snippets.

@swimmi
Created April 22, 2014 09:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save swimmi/11172167 to your computer and use it in GitHub Desktop.
Save swimmi/11172167 to your computer and use it in GitHub Desktop.
Output each password is or not acceptable
#include <fstream>
#include <iostream>
using namespace std;
//Output each password is or not acceptable.
int main()
{
//ifstream cin("easier_done_than_said.txt");
string s;
int a,b; //count of consecutive vowels and consonants
bool c1,c2,c3,is; //fill rules 1-3 and consecutive or not
string vs="aeiou";
while(cin>>s)
{
if(s=="end") break;
c1=is=false;c2=c3=true;a=b=1;
for(int i=0;i<s.length();i++)
{
int n=vs.find(s[i]); //index of vowel
if(n!=-1)
{
if(is) a++;
if(a>2) c2=false; //more than 2 consecutive vowels
c1=true; //at least one vowel
b=1;is=true;
}
else
{
if(!is) b++;
if(b>2) c2=false; //more than 2 consecutive consonants
a=1;is=false;
}
if(i>0&&s[i]==s[i-1]&&n%2!=1) //two consecutive and same letter
c3=false;
}
if(c1&&c2&&c3)
cout<<"<"<<s<<"> is acceptable."<<endl;
else
cout<<"<"<<s<<"> is not acceptable."<<endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment