高级游戏开发工程师测试题要求:代码要求能够直接编译运行1.实现一个函数:凑14;输入很多个整数(1数值13
高级游戏开发工程师测试题
要求:代码要求能够直接编译运行
1.实现一个函数:凑14;输入很多个整数(1<=数值<=13),任意两个数相加等于14就可以从数组中删除这两个数,求剩余数(按由小到大排列);
比如: 输入数组[9,1,9,7,5,13], 输出数组[7,9]
2.实现一个函数:线段重叠; 输入多个一维线段,求出这些线段相交的所有区域(也用线段表示); 一条线段用两个值表示(x0,x1), 其中x1>x0;
比如: 输入线段数组[(2,4),(1.5,6),(0.5,3.5),(5,7),(7.5,9)], 输出线段数组[(1.5,4),(5,6)]
3.实现一个函数:最长顺子;输入很多个整数(1<=数值<=13),返回其中可能组成的最长的一个顺子(顺子中数的个数代表顺的长度); 其中数字1也可以代表14; 顺子包括单顺\双顺\3顺;单顺的定义是连续5个及以上连续的数,比如1,2,3,4,5、3,4,5,6,7,8和10,11,12,13,1等;双顺的定义是连续3个及以上连续的对(对:两个相同的数被称为对),比如1,1,2,2,3,3、4,4,5,5,6,6,7,7和11,11,12,12,13,13,1,1等;3顺的定义是连续2个及以上连续的3张(3张:3个相同的数被称为3张),比如1,1,1,2,2,2、3,3,3,4,4,4,5,5,5,6,6,6和13,13,13,1,1,1等等;
比如:输入数组[1,5,2,3,4,4,5,9,6,7,2,3,3,4], 输出数组[2,2,3,3,4,4,5,5]
4.设计一个程序:使用多线程,统计程序源代码行数;源代码是可以编译通过的合法的代码,统计其物理总行数、其中的空行行数、其中含有有效代码的行数、其中含有注释内容的行数;(要求必须利用多线程编程,如果代码框架能更容易的扩展到支持多种语言的源代码行数统计,将获得更高的评价。)
第二题
package com.huawei.oms.pm.ui.test;public class Point { double x; double y; public Point(double x, double y) { this.x = x; this.y = y; } /** * @return 返回 x */ public double getX() { return x; } /** * @param 对x进行赋值 */ public void setX(double x) { this.x = x; } /** * @return 返回 y */ public double getY() { return y; } /** * @param 对y进行赋值 */ public void setY(double y) { this.y = y; }}
package com.huawei.oms.pm.ui.test;import java.util.ArrayList;import java.util.Arrays;import java.util.List;public class Test { static int[] cards = new int[] { 1, 5, 2, 3, 4, 4, 5, 9, 6, 7, 2, 3, 3, 4 }; public static void main(String[] args) { Arrays.sort(cards); // 顺子 List<Integer> result = getResult(0, 5); for (Integer integer : result) { System.out.print(integer); } System.out.println(); // 连队 List<Integer> result1 = getResult(1, 4); for (Integer integer : result1) { System.out.print(integer); } System.out.println(); // 飞机 List<Integer> result2 = getResult(2, 6); for (Integer integer : result2) { System.out.print(integer); } System.out.println(); } private static List<Integer> getResult(int order, int size) { List<Integer> list = new ArrayList<Integer>(); for (int i = 0; i < cards.length; i++) { if (order == 0) { if (i < cards.length - 1 && cards[i] < cards[i + 1]) { list.add(cards[i]); } continue; } else { if (i > order && cards[i] == cards[i - order]) { continue; } if (cards.length >= i + 1 + order && cards[i] == cards[i + order]) { int j = i; for (; j <= i + order; j++) { list.add(cards[j]); } i = j - 1; continue; } } if (list.size() < size) { list = new ArrayList<Integer>(); } } return list; }} public static void getGroup() { // (2,4),(1.5,6),(0.5,3.5),(5,7),(7.5,9)] // [(1.5,4),(5,6)] for (int i = 0; i < plist.size(); i++) { List<Point> list = new ArrayList<Point>(); Point previou = plist.get(i); list.add(previou); for (int j = 0; j < plist.size(); j++) { Point next = plist.get(j); if (previou.y < next.y && previou.y > next.x) { list.add(next); } } if (list.size() > 1) { maps.put("group" + i, list); } } } public static void init() { Point point1 = new Point(2, 4); Point point2 = new Point(1.5, 6); Point point3 = new Point(0.5, 3.5); Point point4 = new Point(5, 7); Point point5 = new Point(7.5, 9); plist.add(point1); plist.add(point2); plist.add(point3); plist.add(point4); plist.add(point5); }}package com.huawei.oms.pm.ui.test;import java.util.ArrayList;import java.util.Arrays;import java.util.HashMap;import java.util.HashSet;import java.util.List;import java.util.Map;import java.util.Set;public class Test { private static List<Point> plist = new ArrayList<Point>(); private static Map<String, List<Point>> maps = new HashMap<String, List<Point>>(); private static Set<String> results = new HashSet<String>(); public static void main(String[] args) { init(); getGroup(); filterArray(); getResult(); for (String str : results) { System.out.println(str); } } public static void getResult() { for (String key : maps.keySet()) { List<Point> list1 = maps.get(key); results.add(getPoint(list1)); } } public static void filterArray() { Set<String> keySet = new HashSet<String>(); for (String key : maps.keySet()) { List<Point> list1 = maps.get(key); Double[] value = getMaxAndMin(list1); for (String key2 : maps.keySet()) { if (key.equals(key2)) { continue; } List<Point> list2 = maps.get(key2); Double[] value2 = getMaxAndMin(list2); if (value[0] <= value2[0] && value[1] >= value2[1]) { keySet.add(key2); } } } for (String str : keySet) { maps.remove(str); } } public static Double[] getMaxAndMin(List<Point> list) { Double[] doubles = new Double[2]; Double min = null; Double max = null; for (Point point : list) { if (min == null || min > point.x) { min = point.x; } if (max == null || max < point.y) { max = point.y; } } doubles[0] = min; doubles[1] = max; return doubles; } public static String getPoint(List<Point> list) { Double[] mins = new Double[list.size()]; Double[] maxs = new Double[list.size()]; for (int i = 0; i < list.size(); i++) { mins[i] = list.get(i).getX(); maxs[i] = list.get(i).getY(); } Arrays.sort(mins); Arrays.sort(maxs); return "(" + mins[1] + "," + maxs[maxs.length - 2] + ")"; }package test;import java.util.Arrays;public class GameOne { public static void main(String[] args) { int[] temp = { 7, 7, 5, 9, 3 }; Arrays.sort(temp); temp = catchGame(temp, 14); for (int i : temp) { System.out.print(i + ","); } } public static int[] catchGame(int[] sum, int catchNumber) { for (int i = 0; i < sum.length; i++) { for (int j = i + 1; j < sum.length; j++) { if (j == i) continue; if (catchNumber == sum[i] + sum[j]) { int numMovedMax = sum.length - (i > j ? i : j) - 1; if (numMovedMax > 0) System.arraycopy(sum, (i > j ? i : j) + 1, sum, i > j ? i : j, numMovedMax); int numMovedMin = sum.length - (i > j ? j : i) - 1; if (numMovedMin > 0) System.arraycopy(sum, (i > j ? j : i) + 1, sum, (i > j ? j : i), numMovedMin); sum = catchGame(Arrays.copyOf(sum, sum.length - 2), catchNumber); continue; } } } return sum; } public static int[] catchNumGame(int[] sum, int catchNumber) { int del = -1; if (del != -1) { if (del != sum.length - 1) System.arraycopy(sum, del + 1, sum, del, sum.length - del - 1); System.arraycopy(sum, 1, sum, 0, sum.length - 1); return catchNumGame(Arrays.copyOf(sum, sum.length - 2), catchNumber); } else { return sum; } }}