티스토리 뷰

Algorithm

EOF (End of File)

kingsubin 2020. 8. 29. 14:58

EOF ?

- 데이터가 더 이상 존재하지 않을 때 우리는 EOF (End of Fil) 즉, 파일의 끝이라고 한다.

 

입력의 종료가 정해져 있지 않은 문제

ex) boj 10951 (A+B-4)

https://www.acmicpc.net/problem/10951

 

1. 입력의 종료는 더 이상 읽을 수 있는 데이터 (EOF) 가 없을 때 종료한다.

- Scanner에서 처리하는 방법

- BufferedReader에서 처리하는 방법

 

Scanner in=new Scanner(System.in);
			
while(in.hasNextInt()){
		
	int a=in.nextInt();
	int b=in.nextInt();
	System.out.println(a+b);
		
}	

(1)Scanner

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();
String str;
 
while( (str=br.readLine()) != null ){
		    
	int a = str.charAt(0) - 48;
	int b = str.charAt(2) - 48;
	sb.append(a+b).append("\n");
		
}
System.out.print(sb);

(2)BufferdReader

 

 

 


※참조

st-lab.tistory.com/40

'Algorithm' 카테고리의 다른 글

트리 정리  (0) 2020.09.07
그리디&구현, DFS&BFS  (0) 2020.09.01
LinkedList  (0) 2020.08.31
정렬 정리  (0) 2020.08.27
검색 정리  (0) 2020.07.13