MCPcopy Create free account
hub / github.com/Ayush7614/Daily-Coding-DS-ALGO-Practice / A

Class A

Hackerank/Java/Strong-password.java:23–164  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

21// The code goes as follows:--
22
23public class A {
24
25// A class with name as [A] with a empty string INPUT -
26
27 InputStream is;
28 PrintWriter out;
29 String INPUT = "";
30
31 // The solution function to check the validity of the entered password is correct or not.
32
33 void solve()
34 {
35 String numbers = "0123456789",
36 lower_case = "abcdefghijklmnopqrstuvwxyz",
37 upper_case = "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
38 special_characters = "!@#$%^&*()-+";
39 int n = ni();
40 char[] s = ns(n);
41 int need = 0;
42 int x = 0;
43 for(char c : s){
44 if(numbers.indexOf(c) >= 0)x |= 1;
45 if(lower_case.indexOf(c) >= 0)x |= 2;
46 if(upper_case.indexOf(c) >= 0)x |= 4;
47 if(special_characters.indexOf(c) >= 0)x |= 8;
48 }
49 need = 4-Integer.bitCount(x);
50 out.println(Math.max(6-n, need));
51 }
52
53 void run() throws Exception
54 {
55 is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
56 out = new PrintWriter(System.out);
57
58 long s = System.currentTimeMillis();
59 solve();
60 out.flush();
61 if(!INPUT.isEmpty())tr(System.currentTimeMillis()-s+"ms");
62 }
63
64 public static void main(String[] args) throws Exception { new A().run(); }
65
66 private byte[] inbuf = new byte[1024];
67 public int lenbuf = 0, ptrbuf = 0;
68
69 private int readByte()
70 {
71 if(lenbuf == -1)throw new InputMismatchException();
72 if(ptrbuf >= lenbuf){
73 ptrbuf = 0;
74 try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
75 if(lenbuf <= 0)return -1;
76 }
77 return inbuf[ptrbuf++];
78 }
79
80 private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected