1、题目:现在有45个NPC,有3层,每层5个关卡,每个关卡3个NPC,如果得知NPC的ID如何得到他是第几层,第几关的(妹的,这串代码让哥哥头疼了半天,终于想出来了!我只想骂你妹的)int a = 20int c = a % 15 == 0 ? a / 15 : a / 15 + 1; //层int q = (a - (c - 1) * 15) % 3 == 0 ? (a - (c - 1) * 15) / 3 : (a - (c - 1) * 15) / 3 + 1; //关卡System.out.println(c);System.out.println(q);2、将数列1,2,3,…,n 依次进栈,出栈的第一个数为n,问出栈的第i(1<=i<=n)个数是什么?(简单的面试题,有意思么呵呵)定义一个数组N,他的大小为n。 那么出栈的第i个数字为 N[n-i]3、统计项目中一共多少行代码package xxxx;import java.io.BufferedReader;import java.io.File;import java.io.FileReader;public class CodeCounter {private long normalLines = 0;private long commentLines = 0;private long spaceLines = 0;private long totalLines = 0;private static long a = 0;public CodeCounter(String filePath) {tree(filePath);}private void tree(String filePath) {File file = new File(filePath);File[] childs = file.listFiles();if (childs == null) {parse(file);} else {for (int i = 0; i < childs.length; i++) {System.out.println("path:" + childs.getPath());if (childs.isDirectory()) {tree(childs.getPath());} else {childs.getName().matches(".*.java$");System.out.println("当前" + childs.getName() + "代码行数:");parse(childs);getCodeCounter();}}}}private void parse(File file) {BufferedReader br = null;boolean comment = false;try {br = new BufferedReader(new FileReader(file));String line = "";while ((line = br.readLine()) != null) {line = line.trim();// 去除空格if (line.matches("^[s&&[^n]]*$")) {spaceLines++;} else if ((line.startsWith("")) {commentLines++;comment = true;} else if (true == comment) {commentLines++;if (line.endsWith("*/")) {comment = false;}} else if (line.startsWith("//")) {commentLines++;} else {normalLines++;}}} catch (Exception e) {e.printStackTrace();}}private void getCodeCounter() {totalLines = normalLines + spaceLines + commentLines;a += totalLines;System.out.println("普通代码行数:" + normalLines);System.out.println("空白代码行数:" + spaceLines);System.out.println("注释代码行数:" + commentLines);System.out.println("代码总行数:" + totalLines);normalLines = 0;spaceLines = 0;commentLines = 0;totalLines = 0;}public static void main(String args[]) {CodeCounter counter = new CodeCounter("D:workSpaceXXXsrc");}}


