Practice

Author: Aryan KD
Tester: Aryan KD
Editorialist: Aryan KD

# DIFFICULTY:

CAKEWALK, SIMPLE, EASY.

Math .

# QUICK EXPLANATION:

Should contain concise explanation, clear to advanced coders.

# EXPLANATION:

We have given an string in the form of bank password
but for being a valid bank password bank has some rules for it

• It should not contain any space .
• first letter of password should be a lowercase letter
• password must contain at least one uppercase latter and one numeric digit .

if the password follows above rule than it is valid password otherwise invalid .

we have given string we have to check the condition given above one by one and then find out wether it is valid or not
suppose given string is anu4rG
above string follows all condition for being perfect password
there for output is valid

lets take another example anur2 jhajda
in the above given string there is a space in it therefor it is against the rule of bank password there for output is invalid

simply we have to iterate the given string and if it satisfies all the given condition then print valid else invalid

# SOLUTIONS:

Setter's Solution

#include<bits/stdc++.h>
using namespace std;
void testcase()
{
cin>>ws;
string s;
getline(cin,s);
// cout<<1;
int flag1=0,flag2=0,flag3=0,flag4=0;
if(s[0]>=‘a’&& s[0]<=‘z’){
flag1=1;
}
for(int i=0;i<s.length();i++){
if(s[i]>=‘A’ && s[i]<=‘Z’){
flag2=1;
}
}

for(int i=0;i<s.length();i++){
if(s[i]>=48 && s[i]<=57){
flag3=1;
}
}

for(int i=0;i<s.length();i++){
if(s[i]==’ '){
flag4=1;
}
}

if(flag1 && flag2 && flag3 && !flag4){
cout<<“valid”;
}
else{
cout<<“invalid”;
}
//cout<<flag3;

}
int main()
{
int t;
cin>>t;
while(t–)
{
testcase();
cout<<endl;
}
return 0;
}

Tester's Solution

#include<bits/stdc++.h>
using namespace std;
void testcase()
{
cin>>ws;
string s;
getline(cin,s);
// cout<<1;
int flag1=0,flag2=0,flag3=0,flag4=0;
if(s[0]>=‘a’&& s[0]<=‘z’){
flag1=1;
}
for(int i=0;i<s.length();i++){
if(s[i]>=‘A’ && s[i]<=‘Z’){
flag2=1;
}
}

for(int i=0;i<s.length();i++){
if(s[i]>=48 && s[i]<=57){
flag3=1;
}
}

for(int i=0;i<s.length();i++){
if(s[i]==’ '){
flag4=1;
}
}

if(flag1 && flag2 && flag3 && !flag4){
cout<<“valid”;
}
else{
cout<<“invalid”;
}
//cout<<flag3;

}
int main()
{
int t;
cin>>t;
while(t–)
{
testcase();
cout<<endl;
}
return 0;
}

Editorialist's Solution

#include<bits/stdc++.h>
using namespace std;
void testcase()
{
cin>>ws;
string s;
getline(cin,s);
// cout<<1;
int flag1=0,flag2=0,flag3=0,flag4=0;
if(s[0]>=‘a’&& s[0]<=‘z’){
flag1=1;
}
for(int i=0;i<s.length();i++){
if(s[i]>=‘A’ && s[i]<=‘Z’){
flag2=1;
}
}

for(int i=0;i<s.length();i++){
if(s[i]>=48 && s[i]<=57){
flag3=1;
}
}

for(int i=0;i<s.length();i++){
if(s[i]==’ '){
flag4=1;
}
}

if(flag1 && flag2 && flag3 && !flag4){
cout<<“valid”;
}
else{
cout<<“invalid”;
}
//cout<<flag3;

}
int main()
{
int t;
cin>>t;
while(t–)
{
testcase();
cout<<endl;
}
return 0;
}