/** * 添加一行 * * @param s 行内容 */ public final void addLine(String s) { if (s != null && !s.trim().equals(ZMLTag.NONE_VALUE)) { lines.add(s); } else { lines.add(ZMLTag.NONE_VALUE); } }
/** * 设置当前行号 * * @param n 行号 */ public final void setCurrentLine(int n) { if (lines != null && lines.size() < n) { n = lines.size() - 1; } else if (n < 0) { n = 0; } curLine = n; }
public static void main(String[] args) throws IOException { InputHandler ih = new InputHandler(args[0]); Solution sol = new Solution(); ArrayList<int[]> inIntList = ih.getDataAsIntList(); for (int i = 0; i < inIntList.size(); i++) { int n = inIntList.get(i)[0]; System.out.println(sol.isPalindrome(n)); } }
private ArrayList<Element> sortList(ArrayList<Element> list) { ArrayList<Element> listSorted = new ArrayList<>(); ArrayList<Element> elements = new ArrayList<>(Element.values()); for (Element element : elements) while (list.contains(element)) { list.remove(element); listSorted.add(element); } return listSorted; }
private boolean listContainsEquation( ArrayList<Element> list, ArrayList<Element> equationElement) { ArrayList<Element> listClone = list.clone(); for (Element element : equationElement) { if (listClone.contains(element)) listClone.remove(element); else return false; } return true; }
private ArrayList<Element> removeEquationFromList( ArrayList<Element> list, ArrayList<Element> equationElement) { for (Element element : equationElement) list.remove(element); return list; }
private ArrayList<Element> addEquationToList( ArrayList<Element> list, ArrayList<Element> equationElement) { for (Element element : equationElement) list.add(element); return list; }
public ArrayList<Element> trimElements(ArrayList<Element> list) { ArrayList<Element> listOld = list.clone(); for (ArrayList<Element> equationElement : this.equations.getKeys()) { if (!listContainsEquation(list, equationElement)) continue; list = removeEquationFromList(list, equationElement); list = addEquationToList(list, this.equations.getValue(equationElement)); list = sortList(list); printTrim(equationElement, listOld, list); list = trimElements(list); break; } return list; }
public boolean isPerfectPosition(ArrayList<Element> list) { for (ArrayList<Element> pPosition : this.perfectPositions) { if (pPosition.size() != list.size()) continue; ArrayList<Element> listTemp = list.clone(); boolean notFound = false; for (Element element : pPosition) if (listTemp.contains(element)) listTemp.remove(element); else notFound = true; if (notFound) continue; if (!listTemp.isEmpty()) continue; return true; } return false; }
/** 获取当前行内容 */ public final String getCurrentLine() { // return lines == null ? null : (String) lines.get(curLine); // // 2009/05/21 @modifyby 江威 if (lines == null || curLine < 0 || curLine >= lines.size()) return ""; return (String) lines.get(curLine); }
/** 获取总行数 */ public final int totalLineNum() { return lines == null ? 0 : lines.size(); }
public final void remove(int index) { lines.remove(index); }
/** 销毁 */ public final void release() { if (lines != null) { lines.removeAll(); lines = null; } }
/** 获取指定行内容 */ public final String getLine(int n) { if (lines == null || n < 0 || n >= lines.size()) return ZMLTag.NONE_VALUE; return (String) lines.get(n); }