Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
用各位的数据测试没问题,可是runtime error,好奇怪package acm; import java.util.Arrays; import java.util.Scanner; /** * Created by liduo on 2017/11/28. */ public class ACM1010STAMPS { static Integer[] bestSolution; static Integer max = 0; static Integer size = 0; static Integer types = 0; static boolean tie = false; private static void changeResult(Integer[] solution, Integer m, Integer s, Integer ts, boolean t){ bestSolution = solution; max = m; size = s; types = ts; tie = t; } private static void printResult(Integer customer){ if(bestSolution == null){ System.out.println(customer + " ---- none"); }else if(tie){ System.out.println(customer + " (" + types + "): tie"); }else{ Arrays.sort(bestSolution); String result = null; for(int i = 0; i < bestSolution.length; i ++){ if(i == 0){ result = bestSolution[i].toString(); }else{ result += " " + bestSolution[i]; } } System.out.println(customer + " (" + types + "): " + result); } } private static void initResult(){ bestSolution = null; max = 0; size = 0; types = 0; tie = false; } public static void main(String[] args){ Scanner scanner = new Scanner(System.in); while(scanner.hasNext()){ String stampsStr = scanner.nextLine().trim(); String customersStr = scanner.nextLine().trim(); String[] stampStrs = stampsStr.substring(0, stampsStr.length() - 1).split(" "); String[] customerStrs = customersStr.substring(0, customersStr.length() - 1).split(" "); Integer[] stamps = new Integer[stampStrs.length]; Integer[] customers = new Integer[customerStrs.length]; for(int i = 0; i < stampStrs.length; i++){ stamps[i] = Integer.valueOf(stampStrs[i]); } for(int i = 0; i < customerStrs.length ; i++){ customers[i] = Integer.valueOf(customerStrs[i]); } for(Integer customer : customers){ for(int i1 = 0; i1 < stamps.length; i1++){ if(stamps[i1].equals(customer)){ int currentTypes = 1; if(types > currentTypes){ continue; }else if(types.equals(currentTypes)) { if (1 > size) { changeResult(new Integer[]{stamps[i1]}, stamps[i1], 1 ,1 ,false); } else if (size == 1) { tie = true; } }else{ changeResult(new Integer[]{stamps[i1]}, stamps[i1], 1 ,1 ,false); } } for(int i2 = i1; i2 < stamps.length; i2++){ if(customer.equals(stamps[i1] + stamps[i2])){ int currentTypes = i1 == i2 ? 1 : 2; Integer[] result = new Integer[]{stamps[i1], stamps[i2]}; int currentMax = Math.max(stamps[i1], stamps[i2]); if(types > currentTypes){ continue; }else if(types.equals(currentTypes)) { if (2 > size && size > 0) { continue; } else if (size == 2) { if(max > currentMax){ continue; }else if(max == currentMax){ tie = true; }else{ changeResult(result, currentMax, 2, currentTypes, false); } }else{ changeResult(result, currentMax, 2, currentTypes, false); } }else{ changeResult(result, currentMax, 2, currentTypes, false); } } for(int i3 = i2; i3 < stamps.length; i3++){ if(customer.equals(stamps[i1] + stamps[i2] + stamps[i3])) { int currentTypes = 1; if (i1 != i2) { currentTypes = 2; } if (i1 != i3 && i2 != i3) { currentTypes++; } Integer[] result = new Integer[]{stamps[i1], stamps[i2], stamps[i3]}; int currentMax = Math.max(stamps[i1], stamps[i2]); currentMax = Math.max(stamps[i3], currentMax); if(types > currentTypes){ continue; }else if(types.equals(currentTypes)){ if(3 > size && size > 0){ continue; }else if(size.equals(3)){ if(max > currentMax){ continue; }else if(max.equals(currentMax)){ tie = true; }else{ changeResult(result, currentMax, 3, currentTypes, false); } }else{ changeResult(result, currentMax, 3, currentTypes, false); } }else{ changeResult(result, currentMax, 3, currentTypes, false); } } for(int i4 = i3; i4 < stamps.length; i4++){ if(customer.equals(stamps[i1] + stamps[i2] + stamps[i3] + stamps[i4])){ int currentTypes = 1; if(i1 != i2){ currentTypes = 2; } if(i1 != i3 && i2 != i3){ currentTypes ++; } if(i4 != i1 && i4 != i2 && i4 != i3){ currentTypes ++; } Integer[] result = new Integer[]{stamps[i1], stamps[i2], stamps[i3], stamps[i4]}; int currentMax = Math.max(stamps[i1], stamps[i2]); currentMax = Math.max(currentMax, stamps[i3]); currentMax = Math.max(currentMax, stamps[i4]); if(types > currentTypes){ continue; }else if(types.equals(currentTypes)){ if(4 > size && size > 0){ continue; }else if(size.equals(4)){ if(max > currentMax){ continue; }else if(max.equals(currentMax)){ tie = true; }else{ changeResult(result, currentMax, 4, currentTypes, false); } }else{ changeResult(result, currentMax, 4, currentTypes, false); } }else{ changeResult(result, currentMax, 4, currentTypes, false); } } } } } } printResult(customer); initResult(); } } } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator