Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |
Tags
- 자바
- BFS
- 프로젝트
- DFS
- 그래프
- 스프링
- programmers
- OS
- algorithm
- 코틀린
- LEVEL2
- DP
- 알고리즘
- 네트워크
- 자료구조
- back-end
- Java8
- Spring
- kotlin
- 프로그래머스
- java
- lambda
- backtracking
- baekjoon
- 백트래킹
- TDD
- 모던자바
- 운영체제
- 백준
- Brute-force
Archives
- Today
- Total
요깨비's LAB
[hacker-rank, 문자열, Java] Strong Password 본문
https://www.hackerrank.com/challenges/strong-password/problem?h_r=next-challenge&h_v=zen
import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.function.*;
import java.util.regex.*;
import java.util.stream.*;
import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toList;
class Result {
/*
* Complete the 'minimumNumber' function below.
*
* The function is expected to return an INTEGER.
* The function accepts following parameters:
* 1. INTEGER n
* 2. STRING password
*/
public static int minimumNumber(int n, String password) {
int minimumNumber = 0;
// Return the minimum number of characters to make the password strong
Pattern p1 = Pattern.compile("[0-9]");
int isContainDigit = p1.matcher(password).find() ? 0 : 1;
minimumNumber += isContainDigit;
Pattern p2 = Pattern.compile("[a-z]");
int isContainLowerCase = p2.matcher(password).find() ? 0 : 1;
minimumNumber += isContainLowerCase;
Pattern p3 = Pattern.compile("[A-Z]");
int isContainUpperCase = p3.matcher(password).find() ? 0 : 1;
minimumNumber += isContainUpperCase;
Pattern p4 = Pattern.compile("[!@#$%^&*()\\-+]");
int isContainSpecialChar = p4.matcher(password).find() ? 0 : 1;
minimumNumber += isContainSpecialChar;
int isSatisfyLen = 0;
int currentLen = n + minimumNumber;
if (currentLen < 6) {
return 6 - currentLen + minimumNumber;
}
return minimumNumber;
}
}
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH")));
int n = Integer.parseInt(bufferedReader.readLine().trim());
String password = bufferedReader.readLine();
int answer = Result.minimumNumber(n, password);
bufferedWriter.write(String.valueOf(answer));
bufferedWriter.newLine();
bufferedReader.close();
bufferedWriter.close();
}
}
'알고리즘(Java) > 문자열처리' 카테고리의 다른 글
[hacker-rank, 문자열, Java] Two Characters (0) | 2021.10.05 |
---|
Comments