반응형
1. 10952
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
public class Main {
public static void main(String[] args) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
String[] nums = null;
do {
nums = br.readLine().split(" ");
if(nums[0].equals("0") && nums[1].equals("0"))break;
} while(true);
}
}
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
|
2. 10951
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
public class ScannerMain {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
while(scan.hasNextInt()) {
int firstNum = scan.nextInt();
int secondNum = scan.nextInt();
System.out.println(firstNum + secondNum);
}
}
}
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
|
BufferedReader를 사용한 end of file구현을 백준에선 계속 런타임에러로 인식이되서 포기... 나중에 수정예정
edit: 해결했습니다! while문에서 만약 br.readLine를 사용하면 readLine이 while문 부터 작동을해서 런타임에러로 인식을 했습니다. 그래서 readLine를 while문에서 한번적어주면 null빈칸이 올때까지 계속 실행합니다. eof
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
|
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
public class Main {
public static void main(String[] args) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
String temp = " ";
while((temp = br.readLine())!= null) {
String[] numbers = temp.split(" ");
try {
int firstNum = Integer.parseInt(numbers[0]);
int secondNum = Integer.parseInt(numbers[1]);
int result = firstNum + secondNum;
} catch (Exception e) {
continue;
}
}
}
}
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
|
3. 1110
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
|
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
public class Main {
public static int result(int number) {
int result = number;
int cnt = 0;
do {
int a = result % 10;
int b = result / 10;
result = (a * 10) + (a + b) % 10;
cnt ++;
}while(number != result);
return cnt;
}
public static void main(String[] args) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int number = Integer.parseInt(br.readLine());
}
}
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
|
반응형
'IT > 알고리즘' 카테고리의 다른 글
백준 5단계(2562) (0) | 2019.11.24 |
---|---|
백준 5단계(10818) (0) | 2019.11.23 |
백준 3단계(11/23/19)(2739, 10950, 8393, 15552, 2741, 2742, 11021, 11022, 2438, 2439, 10871) (0) | 2019.11.23 |
백준 2단계(11/23/19)(1330, 9498, 2753, 2884, 10817) (0) | 2019.11.23 |
백준 1단계(11/23/19)(2557, 10718, 10171, 10172, 7287, 1000, 1001, 10998, 1008, 10869, 10430, 2588) (0) | 2019.11.23 |