算法题
[此贴子已经被作者于2018-6-6 13:40编辑过]
public class Test { // 4 4 // 1 2 3 0 // 5 5 // 0 0 2 7 8 // 0 0 public static void main(String[] args) { Scanner scan = new Scanner(System.in); String line = null; List<String> list = new ArrayList<>(); while(!"0 0".equals((line=scan.nextLine()).trim())){ list.add(line); } scan.close(); System.out.println(list); for(int i = 0; i + 1 < list.size(); i += 2) { int q = Integer.parseInt(list.get(i).trim().split(" ")[1]); int mod = 0; for(String val : list.get(i+1).trim().split(" ")) { if(Integer.parseInt(val)%q>mod) { mod = Integer.parseInt(val)%q; } } System.out.println(mod); } } }