Author: Anurag dubey
Tester: Anurag dubey
Editorialist: Anurag dubey
DIFFICULTY:
CAKEWALK, SIMPLE, EASY.
PREREQUISITES:
Math . greedy, bruteforce,string, bit,
PROBLEM:
In given problem we have given string in that string we we have some condition if string satisfied given condition print 1 else print 0,
given string is valid password if it satisfies below condition:
- at least 4 characters
- at least one numeric digit
- at least one capital letter
- must not have space or slash (/)
- starting character must not be a number
QUICK EXPLANATION:
First we will check the condition and do according to condition we will satisfied the all condition and if satisfied then we will print 1 else 0 .
we will take all character one by one and satisfied all condition if it satisfied then print 1 else 0.
EXPLANATION:
In given problem we have given string and we have to satisfies some condition and if it satisfied then print 1 else 0,
for example if given string is asaA2 first we will check first condition it is more than 4 element then it satisfied first condition.
here 2 is numeric digit which satisfied 2nd condition
here A is in capital latter in given string it will satisfied third condition as well
here is no space and not a / also and
in start there is no numeric digit that is it satisfied all the condition hence o/p will 1 .
SOLUTIONS:
Setter's Solution
-
#include<bits/stdc++.h>
-
using namespace std;
- bool ispass(string s,int k){
-
if(k<4){
-
return false;
-
}
- if(s[0]>=48 && s[0]<=57){
-
return false;
-
}
-
bool for_capital =false;
-
bool for_numeric =false;
-
for(int i=0;i<k;i++){
-
if(s[i]==’ ’ || s[i]==‘/’){
-
return false;
-
}
-
else if(s[i]>=65 && s[i]<=90){
-
for_capital=true;
-
}
-
else if(s[i]>=48 && s[i]<=57){
-
for_numeric=true;
-
}
- }
- return(for_numeric && for_capital);
-
}
-
int main()
-
{
-
int t;
-
cin>>t;
-
while(t–){
- cin>>ws;
-
string s;
-
getline(cin,s);
-
int k=0;
-
for(int i=0;s[i]!=‘\0’;i++){
-
k++;
-
}
-
cout<<ispass(s,k);
-
cout<<endl;
-
}
-
return 0;
-
}
Tester's Solution
-
#include<bits/stdc++.h>
-
using namespace std;
- bool ispass(string s,int k){
-
if(k<4){
-
return false;
-
}
- if(s[0]>=48 && s[0]<=57){
-
return false;
-
}
-
bool for_capital =false;
-
bool for_numeric =false;
-
for(int i=0;i<k;i++){
-
if(s[i]==’ ’ || s[i]==‘/’){
-
return false;
-
}
-
else if(s[i]>=65 && s[i]<=90){
-
for_capital=true;
-
}
-
else if(s[i]>=48 && s[i]<=57){
-
for_numeric=true;
-
}
- }
- return(for_numeric && for_capital);
-
}
-
int main()
-
{
-
int t;
-
cin>>t;
-
while(t–){
- cin>>ws;
-
string s;
-
getline(cin,s);
-
int k=0;
-
for(int i=0;s[i]!=‘\0’;i++){
-
k++;
-
}
-
cout<<ispass(s,k);
-
cout<<endl;
-
}
-
return 0;
-
}
Editorialist's Solution
-
#include<bits/stdc++.h>
-
using namespace std;
- bool ispass(string s,int k){
-
if(k<4){
-
return false;
-
}
- if(s[0]>=48 && s[0]<=57){
-
return false;
-
}
-
bool for_capital =false;
-
bool for_numeric =false;
-
for(int i=0;i<k;i++){
-
if(s[i]==’ ’ || s[i]==‘/’){
-
return false;
-
}
-
else if(s[i]>=65 && s[i]<=90){
-
for_capital=true;
-
}
-
else if(s[i]>=48 && s[i]<=57){
-
for_numeric=true;
-
}
- }
- return(for_numeric && for_capital);
-
}
-
int main()
-
{
-
int t;
-
cin>>t;
-
while(t–){
- cin>>ws;
-
string s;
-
getline(cin,s);
-
int k=0;
-
for(int i=0;s[i]!=‘\0’;i++){
-
k++;
-
}
-
cout<<ispass(s,k);
-
cout<<endl;
-
}
-
return 0;
-
}