[BaekJoon] #2083 - 럭비 클럽 [Java][C++]
[BaekJoon] #2083 - 럭비 클럽 [Java][C++]
1. 아이디어
조건문을 활용해서 나이와 몸무게를 기준으로 분기 처리만 하면 된다.
2. 복잡도
| 접근 | 시간 | 공간 |
|---|---|---|
| 풀이 | $O(N)$ | $O(1)$ |
($N$ = 입력 줄 수. Java는 전체 출력을 StringBuilder에 모았다가 출력하므로 공간 $O(N)$)
3. 코드
풀이 [Java][C++]
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
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();
StringTokenizer st;
while (true) {
st = new StringTokenizer(br.readLine());
String name = st.nextToken();
int age = Integer.parseInt(st.nextToken());
int weight = Integer.parseInt(st.nextToken());
if (name.equals("#") && age == 0 && weight == 0) break;
if (age > 17 || weight >= 80) {
sb.append(name).append(" Senior\n");
} else {
sb.append(name).append(" Junior\n");
}
}
System.out.println(sb);
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
while (true) {
string name;
int age, weight;
cin >> name >> age >> weight;
if (name == "#" && age == 0 && weight == 0) break;
if (age > 17 || weight >= 80) {
cout << name << " Senior\n";
} else {
cout << name << " Junior\n";
}
}
}
This post is licensed under CC BY 4.0 by the author.