# Dashrath_mobile , https://www.codechef.com/BEST2021/problems/DASMOB

Practice

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
1. #include<bits/stdc++.h>

2. using namespace std;

• bool ispass(string s,int k){
1. if(k<4){

2. return false;

3. }

• if(s[0]>=48 && s[0]<=57){
1. return false;

2. }

3. bool for_capital =false;

4. bool for_numeric =false;

5. for(int i=0;i<k;i++){

6. if(s[i]==’ ’ || s[i]==‘/’){

7. return false;

8. }

9. else if(s[i]>=65 && s[i]<=90){

10. for_capital=true;

11. }

12. else if(s[i]>=48 && s[i]<=57){

13. for_numeric=true;

14. }

• }
1. return(for_numeric && for_capital);
• }

• int main()

1. {

2. int t;

3. cin>>t;

4. while(t–){

• cin>>ws;
1. string s;

2. getline(cin,s);

3. int k=0;

4. for(int i=0;s[i]!=‘\0’;i++){

5. k++;

6. }

7. cout<<ispass(s,k);

8. cout<<endl;

9. }

10. return 0;

11. }

Tester's Solution
1. #include<bits/stdc++.h>

2. using namespace std;

• bool ispass(string s,int k){
1. if(k<4){

2. return false;

3. }

• if(s[0]>=48 && s[0]<=57){
1. return false;

2. }

3. bool for_capital =false;

4. bool for_numeric =false;

5. for(int i=0;i<k;i++){

6. if(s[i]==’ ’ || s[i]==‘/’){

7. return false;

8. }

9. else if(s[i]>=65 && s[i]<=90){

10. for_capital=true;

11. }

12. else if(s[i]>=48 && s[i]<=57){

13. for_numeric=true;

14. }

• }
1. return(for_numeric && for_capital);
• }

• int main()

1. {

2. int t;

3. cin>>t;

4. while(t–){

• cin>>ws;
1. string s;

2. getline(cin,s);

3. int k=0;

4. for(int i=0;s[i]!=‘\0’;i++){

5. k++;

6. }

7. cout<<ispass(s,k);

8. cout<<endl;

9. }

10. return 0;

11. }

Editorialist's Solution
1. #include<bits/stdc++.h>

2. using namespace std;

• bool ispass(string s,int k){
1. if(k<4){

2. return false;

3. }

• if(s[0]>=48 && s[0]<=57){
1. return false;

2. }

3. bool for_capital =false;

4. bool for_numeric =false;

5. for(int i=0;i<k;i++){

6. if(s[i]==’ ’ || s[i]==‘/’){

7. return false;

8. }

9. else if(s[i]>=65 && s[i]<=90){

10. for_capital=true;

11. }

12. else if(s[i]>=48 && s[i]<=57){

13. for_numeric=true;

14. }

• }
1. return(for_numeric && for_capital);
• }

• int main()

1. {

2. int t;

3. cin>>t;

4. while(t–){

• cin>>ws;
1. string s;

2. getline(cin,s);

3. int k=0;

4. for(int i=0;s[i]!=‘\0’;i++){

5. k++;

6. }

7. cout<<ispass(s,k);

8. cout<<endl;

9. }

10. return 0;

11. }