Created
March 6, 2015 16:47
-
-
Save mahadirz/4a037e8d2bd3c7226a85 to your computer and use it in GitHub Desktop.
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
/** | |
* @author Mahadir Ahmad | |
**/ | |
#include <iostream> | |
#include <fstream> | |
#include <string> | |
using namespace std; | |
bool isValid(string strSecurityAlphabet) | |
{ | |
int iAsciiCode; | |
char cprev; | |
//rule 1 | |
if(strSecurityAlphabet.length() <= 2 || strSecurityAlphabet.length() >= 27) | |
return false; | |
//rule 2 | |
for (unsigned i=0; i<strSecurityAlphabet.length(); ++i) | |
{ | |
iAsciiCode = (int) strSecurityAlphabet.at(i); | |
if(iAsciiCode < 65 || iAsciiCode > 90 ) | |
return false; | |
} | |
//rules 3 | |
for (int i = 0; i < strSecurityAlphabet.length(); i++) | |
{ | |
for (int j = i + 1; j < strSecurityAlphabet.length();) | |
{ | |
if (strSecurityAlphabet[i] == strSecurityAlphabet[j]) | |
{ | |
return false; | |
} else | |
{ | |
j++; | |
} | |
} | |
} | |
return true; | |
} | |
int main () { | |
string line; | |
ifstream myfile ("A.in"); | |
int lineNo=0; | |
if (myfile.is_open()) | |
{ | |
while ( getline (myfile,line) ) | |
{ | |
if(lineNo==0) | |
{ | |
lineNo++; | |
continue; | |
} | |
if(isValid(line)) | |
cout << "Case #" << lineNo << ": VALID" << endl; | |
else | |
cout << "Case #" << lineNo << ": INVALID" << endl; | |
lineNo++; | |
} | |
myfile.close(); | |
} | |
else cout << "Unable to open file"; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment