회원가입
로그인
Toggle navigation
문제
문제
전체 문제
문제 출처
단계별로 풀어보기
알고리즘 분류
추가된 문제
문제 순위
문제
푼 사람이 한 명인 문제
아무도 못 푼 문제
최근 제출된 문제
최근 풀린 문제
랜덤
출처
ICPC
Olympiad
한국정보올림피아드
한국정보올림피아드시․도지역본선
전국 대학생 프로그래밍 대회 동아리 연합
대학교 대회
카카오 코드 페스티벌
Coder's High
ICPC
Regionals
World Finals
Korea Regional
Africa and the Middle East Regionals
Europe Regionals
Latin America Regionals
North America Regionals
South Pacific Regionals
문제집
대회
1
채점 현황
랭킹
게시판
그룹
더 보기
재채점 기록
블로그
강의
실험실
도움말
BOJ Stack
BOJ Book
전체
공지
자유
질문
오타/오역/요청
게시판 공지
홍보
업데이트
solved.ac
글쓰기
질문 도움말
자주묻는 질문
예제는 맞았는데, 다른 예제에서 틀린건지 잘 모르겠습니다.
1759번 - 암호 만들기
ows88
8년 전
0
DFS를 사용하여 구현하였습니다.
어느 예제에서 잘못된 것인지 감이 오지가 않아서 질문 올립니다.
import java.util.Scanner; public class Main { //이 문제는 그냥 DFS로 돌려버리면 된다. char[] passwordWord; char[] password; char[] m={'a','e','i','o','u'}; public Main(int length, int count) { // TODO Auto-generated constructor stub passwordWord = new char[count]; password = new char[length]; } public void generatePassword() { int n=0; for(int i=0; i<passwordWord.length;i++){ dfs(passwordWord,n,i); n=0; } } public void dfs(char[] passwordWord, int n,int i){ if(n!=0) if(password[n-1] >= passwordWord[i]){ n--; return ; } if(n==password.length-1){ //다 됐다면 자모음 비교 int mc=0,ac=0; password[n]=passwordWord[i]; for(int k=0;k<password.length;k++){ for(int f=0;f<m.length;f++){ if(password[k]==m[f]){ mc++; }else ac++; } } if(mc < 1 || ac <2){ n--; return; }else System.out.println(password); return; } password[n]=passwordWord[i]; n++; for(i=0;i<passwordWord.length;i++){ //해당으로부터 첨부터 다시 쭉 dfs(passwordWord,n,i); } } public static void main(String[] args) { // TODO Auto-generated method stub int length=0, count=0; Scanner scanner = new Scanner(System.in); length = scanner.nextInt(); count = scanner.nextInt(); scanner.nextLine(); Main c = new Main(length, count); String temp = scanner.nextLine(); scanner.nextLine(); temp=temp.replaceAll(" ", ""); // System.out.println(temp.trim()); for(int i=0; i<count; i++){ c.passwordWord[i]=temp.charAt(i); // System.out.printf("%c",c.passwordWord[i]); } c.generatePassword(); } }
댓글을 작성하려면
로그인
해야 합니다.
ows88 8년 전
DFS를 사용하여 구현하였습니다.
어느 예제에서 잘못된 것인지 감이 오지가 않아서 질문 올립니다.