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 |
Tags
- 운영체제
- 모던자바
- java
- 자바
- Brute-force
- kotlin
- back-end
- backtracking
- 그래프
- 네트워크
- lambda
- OS
- baekjoon
- LEVEL2
- BFS
- 알고리즘
- 백준
- DP
- algorithm
- DFS
- 코틀린
- 프로그래머스
- programmers
- 스프링
- TDD
- 프로젝트
- Java8
- 자료구조
- 백트래킹
- Spring
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
https://www.hackerrank.com/challenges/strong-password/problem?h_r=next-challenge&h_v=zen
www.hackerrank.com
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