[BOJ 9086] 문자열
Baekjoon Online Judge 9086(Java 11)
[문자열] 문제 풀이
[BOJ 9086] 문자열
시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
1 초 | 128 MB | 115425 | 72894 | 65409 | 63.689% |
문제
- 문자열을 입력으로 주면 문자열의 첫 글자와 마지막 글자를 출력하는 프로그램을 작성하시오.
입력
- 입력의 첫 줄에는 테스트 케이스의 개수 T(1 ≤ T ≤ 10)가 주어진다. 각 테스트 케이스는 한 줄에 하나의 문자열이 주어진다. 문자열은 알파벳 A~Z 대문자로 이루어지며 알파벳 사이에 공백은 없으며 문자열의 길이는 1000보다 작다.
출력
- 각 테스트 케이스에 대해서 주어진 문자열의 첫 글자와 마지막 글자를 연속하여 출력한다.
예제
1
2
3
4
5
// 입력
3
ACDKJFOWIEGHE
O
AB
1
2
3
4
// 출력
AE
OO
AB
출처
- ICPC > Regionals > Asia Pacific > Korea > Nationwide Internet Competition > Seoul Nationalwide Internet Competition 2003 연습 세션 PB번
- 문제를 번역한 사람: baekjoon
알고리즘 분류
제출
내 제출
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
import java.io.*;
public class Main {
public static void solution() throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int n = Integer.parseInt(br.readLine());
for (int i = 0; i < n; i++) {
String str = br.readLine();
int a = str.length();
System.out.println(String.valueOf(str.charAt(0)) + str.charAt(a - 1)); // 아스키 코드값끼리 정수덧셈을 실행해서 강제적으로 문자열합을 유도함
//System.out.println("" + str.charAt(0) + str.charAt(a - 1));
}
bw.flush();
bw.close();
br.close();
}
public static void main(String[] args) throws IOException {
solution();
}
}
런타임 | 메모리 |
---|---|
120 ms | 16016 KB |
Reference
This post is licensed under CC BY 4.0 by the author.