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
- 10814번
- 자바
- 티스토리챌린지
- 14726번
- 14656번
- 20953번
- 14322번
- 25642번
- 10409번
- Java
- 프로젝트 기획서
- 오블완
- 25576번
- 7489번
- 21964
- 21866번
- 14215번
- Baekjoon
- 1568번
- 1333번
- 5597번
- 1141번
- 14592번
- 14467번
- 나무 공격
- 1362번
- 25904번
- 2355번
- 24267번
- 백준
Archives
- Today
- Total
suheang
[백준] | JAVA, 자바 | 16923번 - 다음 다양한 단어 본문
https://www.acmicpc.net/problem/16923
문제 요약 :
다양한 단어란 모두 다른 알파벳 소문자로만 이루어진 단어를 의미한다. 예를 들어, "codeplus", "coding", "algorithm"은 다양한 단어, "baekjoon", "startlink"는 다양한 단어가 아니다.
다양한 단어 S가 주어졌을 때, 사전 순으로 S의 바로 다음에 오는 다양한 단어를 구해보자.
( 사전 순으로 S의 바로 다음에 오는 다양한 단어를 출력한다. 바로 다음에 오는 단어가 없는 경우에는 -1을 출력 )
문제 풀이 :
더보기
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s = br.readLine();
boolean[] alphabetCheck = new boolean[26];
for (int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
alphabetCheck[c - 'a'] = true;
}
char nextAlphabet = ' ';
for (int i = 0; i < alphabetCheck.length; i++) {
if (!alphabetCheck[i]) {
nextAlphabet = (char) ('a' + i);
break;
}
}
if (nextAlphabet != ' ') {
System.out.println(s + nextAlphabet);
} else {
System.out.println(-1);
}
}
}
예제 입력 4번 같은 케이스를 어떻게 처리해야 할지 몰라서 그전까지 구현한 코드를 올림, 추후 수정 예정
'알고리즘' 카테고리의 다른 글
[백준] | JAVA, 자바 | 25192번 - 인사성 밝은 곰곰이 (0) | 2024.05.13 |
---|---|
[백준] | JAVA, 자바 | 17212번 - 달나라 토끼를 위한 구매대금 지불 도우미 (0) | 2024.05.04 |
[백준] | JAVA, 자바 | 16922번 - 로마 숫자 만들기 (0) | 2024.05.03 |
[백준] | JAVA, 자바 | 1758번 - 알바생 강호 (0) | 2024.05.03 |
[백준] | JAVA, 자바 | 1124번 - 온라인 판매 (0) | 2024.05.02 |