I hadn't written it for a while, so I completely forgot. It is a memo that receives input by brain death.
Call the Scanner with the import statement.
python
import java.util.*;
Pass System.in
to the Scanner
class.
python
Scanner sc = new Scanner(System.in);
Let $ S $ be a character string.
python
String S = sc.next();
String S = sc.nextLine();
However, next
recognizes the input value up to the line feed, and nextLine
recognizes up to the blank. For example
S_1 S_2 S_3
Is input, next
reads $ S_1 $ $ S_2 $, and nextLine
reads $ S_1 $.
Let $ x $ be a number. It seems that parsing with ʻInteger.parseInt ()
is about twice as fast.
python
int x = Integer.parseInt(sc.nextLine());
int x = sc.nextInt();
Let $ V_1, V_2, \ cdots V_n $ be the array V
.
python
Integer V[] = new Integer[N];
for (int i=0; i<N; i++) {
V[i] = sc.nextInt();
}
Readability is low if:
python
String a = sc.nextLine();
String[] b = a.split(" ");
int[] c = Stream.of(b).mapToInt(Integer::parseInt).toArray();
Let $ V_1, V_2, \ cdots V_n $ be ListV
.
python
ArrayList<String> V = new ArrayList<String>();
for (int i=0; i<N; i++) {
V[i] = sc.nextInt();
ary.add(word);
}
It seems that you can expect higher speed by making your own Scanner
.
Recommended Posts