Created
April 22, 2014 09:42
-
-
Save swimmi/11172167 to your computer and use it in GitHub Desktop.
Output each password is or not acceptable
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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