Skip to content

Instantly share code, notes, and snippets.

@shahril96
Last active August 29, 2015 14:21
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 shahril96/846b9006101e6398dc8d to your computer and use it in GitHub Desktop.
Save shahril96/846b9006101e6398dc8d to your computer and use it in GitHub Desktop.
#include <iostream>
#include <cctype>
using namespace std;
int validate_input(char input[])
{
char bool_zul[30] = {0}, *ptr = input;
while(*ptr)
{
int index = *ptr - 'A';
// 1. check jika setiap characters dlm string 'input' mengandungi bukan uppercase character (A-Z)
// 2. check jika character dh wujud dalam array -> O(1) performance
if(!isupper(*ptr++) || bool_zul[index] == 1)
{
return 0;
}
else bool_zul[index] = 1;
}
int len = (int)(ptr - input);
return len > 2 && len < 27;
}
int main()
{
int n;
char input[1000];
cin >> n;
cin.ignore();
for(int i = 1; i <= n; i++)
{
cin.getline(input, 1000);
cout << "Case #" << i << ": " << (validate_input(input) ? "VALID" : "INVALID") << endl;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment