A special site for solving fun programming problems and challenges, interested in computer science, programming, basics, data structure and algorithms



 Chef is planning to setup a secure password for his Codechef account. For a password to be secure the following conditions should be satisfied:

1) Password must contain at least one lower case letter [az];

2) Password must contain at least one upper case letter [AZ] strictly inside, i.e. not as the first or the last character;

3) Password must contain at least one digit [09] strictly inside;

4) Password must contain at least one special character from the set { '@', '#', '%', '&', '?' } strictly inside;

5) Password must be at least 10 characters in length, but it can be longer.

Chef has generated several strings and now wants you to check whether the passwords are secure based on the above criteria. Please help Chef in doing so.

Input

  • First line will contain T, number of testcases. Then the testcases follow.
  • Each testcase contains of a single line of input, string S.

Output

For each testcase, output in a single line "YES" if the password is secure and "NO" if it is not.

Constraints

  • 1|S|20
  • All the characters in S are one of the following: lower case letters [az], upper case letters [AZ], digits [09], special characters from the set { '@', '#', '%', '&', '?' }
  • Sum of length of strings over all tests is atmost 106

Sample Input 1 

3
#cookOff#P1
U@code4CHEFINA
gR3@tPWD

Sample Output 1 

NO
YES
NO

Explanation

Example case 1: Condition 3 is not satisfied, because the only digit is not strictly inside.

Example case 2: All conditions are satisfied.

Example case 3: Condition 5 is not satisfied, because the length of this string is 8.

solution in cpp

#include<iostream>
#define ll long long
#include<vector>
#include<climits>
#include<string>
#include<algorithm>
using namespace std;

void solve()
{
	string pass;
	cin >> pass;
	if (pass.length() < 10)
	{
		cout << "NO\n";
	}
	else
	{
		ll l, u, d, sp;
		l = u = d = sp = 0;
		for (ll i = 0; i < pass.length(); i++)
		{
			if (pass[i] >= 97 && pass[i] <= 122)
			{
				l++;
			}
			if (i > 0 && i < pass.length() - 1)
			{
				if (pass[i] >= '0' && pass[i] <= '9')
					d++;
				if (pass[i] >= 65 && pass[i] <= 90)
					u++;
				if (pass[i] == '@' || pass[i] == '#' || pass[i] == '%' || pass[i] == '&' || pass[i] == '?')
					sp++;
			}
		}
		if (l > 0 && u > 0 && d > 0 && sp > 0)
		{
			cout << "YES\n";
		}
		else
		{
			cout << "NO\n";
		}
	}
}

int main()
{

	int t;
	cin >> t;
	while (t--)
	{
		solve();
	}
	
	return 0;
}

No comments:

Post a Comment