// The Weight Of Words
package Bronze_II_2;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;
public class Ex24798 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int l = Integer.parseInt(st.nextToken());
int w = Integer.parseInt(st.nextToken());
if (w < l || w > l * 26) {
System.out.println("impossible");
} else {
char[] s = new char[l];
Arrays.fill(s, 'a');
int currentWeight = l;
for (int i = 0; i < l; i++) {
if (currentWeight == w) {
break;
}
int difference = Math.min(25, w - currentWeight);
s[i] += difference;
currentWeight += difference;
}
String result = new String(s);
System.out.println(result);
}
}
}
이번 문제는 내용을 이해하는데 힘들었다. 처음엔 예시로 "good", "luck", "programming"처럼 완성된 단어로 출력 예시를 보여주길래 완성된 단어를 출력하도록 해야하나 했다. 하지만 브론즈2의 난이도에서 그렇게까지 고난이도의 문제를 내지 않았을 것이라 생각했고, 결론은 문자열의 길이와 가중치만 맞추면 되는 거였다.
'백준 풀이 > 자바(Java)' 카테고리의 다른 글
백준 2774 자바 - 아름다운 수 (0) | 2024.06.24 |
---|---|
백준 31656 자바 - Sticky Keys (0) | 2024.06.24 |
백준 24183 자바 - Affischutskicket (0) | 2024.06.22 |
백준 7130 자바 - Milk and Honey (0) | 2024.06.21 |
백준 30007 자바 - 라면 공식 (0) | 2024.06.20 |