(Problem solution in Java.) import java.io.*; import java.util.*; public class Solution { public static void main(String[] args) { /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */ Scanner in = new Scanner(System.in); ...
importjava.io.*;importjava.util.*;importjava.math.BigInteger;publicclassSolution{publicstaticvoidmain(String[] args)throwsIOException{BufferedReaderbufferedReader=newBufferedReader(newInputStreamReader(System.in));Stringa=bufferedReader.readLine();Stringb=bufferedReader.readLine(); bufferedReader.close();Bi...
只是在这个问题中,数组中的数是有可能重复的,所以map中的value要用一个arrayList保存。 另外注意找的时候要保持i比在map中找到的坐标小(如代码26行的判断所示),以免重复。 代码如下: 1importjava.util.*;23publicclassSolution {4publicstaticvoidmain(String[] args) {5Scanner in =newScanner(System.in);6int...
import java.io.*; import java.util.*;public class Solution { private static InputReader in; private static PrintWriter out;public static void main(String[] args) throws IOException { in = new InputReader(System.in); out = new PrintWriter(System.out, true);int n = in.nextInt(); ...
public class Solution { public static void main(String[] args) { int i = 0; Scanner scanner = new Scanner(System.in); while(scanner.hasNext()){ System.out.printf("%d %s\n",++i, (String)scanner.nextLine()); } } }
水题:维护一个ArrayList和记录当前最小距离的变量miniDist,每当i和i+1两个数的距离和miniDist相等时,把i放到ArrayList里面;当两个数距离小于miniDist时,把ArrayList清空,i放进去,并更新miniDist;最后根据ArrayList输出答案。 代码如下: 1importjava.util.*;23publicclassSolution {4publicstaticvoidmain(String[] arg...
1 <=x<= 10000 ,x ∈ B Xmax-Xmin< 101 题解:设置两个数组,因为x的范围在1~10000之间,只要开两个10001的数组分别记录A和B中元素的个数,然后比较两个数组就可以了。 代码如下: 1importjava.util.*;23publicclassSolution {4publicstaticvoidmain(String[] args) {5Scanner in =newScanner(System.in);...
另外,java中的hashset是无需的,treeset是有序的。 代码如下: 1importjava.io.*;2importjava.util.*;345publicclassSolution {67publicstaticvoidmain(String[] args) {8Scanner in =newScanner(System.in);9intt =in.nextInt();10for(inti = 0; i < t; i++){11Set<Long> answer=ManasaandStones(...
1importjava.io.BufferedReader;2importjava.io.IOException;3importjava.io.InputStreamReader;4importjava.nio.Buffer;5importjava.util.*;6classSolution{7privatestaticintnumberOfItems = 0;8privatestaticvoidadd(intnumber,ArrayList<Integer>a){9intpositon =Collections.binarySearch(a, number);10if(positon<0...