8.27 网易互娱笔试
2个半小时 3道编程题
第一题 铺墙纸 简单找找规律挺简单,只不过处理数据需要细心耐心一点
第二题 找有效矩形面积 判断相交然后计算矩形面积然后减去重合的面积即可(难度不大,但是自己还是太菜了,最后才发现要减去重合面积,已经来不及了....)
第三题 手势密码 完全没思路没时间
有心理准备网易的笔试会很难,准备了很久很久还是不如人意。无论什么原因都只是借口,只能怪自己能力还是太差了。
贴一下第一题ac代码
public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int T = Integer.parseInt(sc.nextLine()); List<char[][]> data1 = new ArrayList<>(); int[][] data2 = new int[T][2]; for (int i = 0; i < T; i++) { String[] info = sc.nextLine().split(" "); int n = Integer.parseInt(info[0]); int m = Integer.parseInt(info[1]); char[][] room = new char[n][n]; for (int j = 0; j < n; j++) { String rowStr = sc.nextLine(); char[] row = rowStr.toCharArray(); for (int k = 0; k < row.length; k++) { room[j][k] = row[k]; } } data1.add(room); data2[i][0] = n; data2[i][1] = m; if (i != T - 1) { sc.nextLine(); } } for (int i = 0; i < data1.size(); i++) { getResult(data1.get(i), data2[i][0], data2[i][1]); } } public static void getResult(char[][] room, int n, int m) { // 求差值 也就是扩容的次数 int diff = (m - n) / 2; // 扩容后的数组 char[][] result = new char[m][m]; int leftBoundary = diff; int rightBoundary = diff + n - 1; int topBoundary = diff; int bottomBoundary = diff + n - 1; // 把原数组填进去 for (int i = topBoundary; i <= bottomBoundary; i++) { for (int j = leftBoundary; j <= rightBoundary; j++) { result[i][j] = room[i - diff][j - diff]; } } for (int i = 0; i < diff; i++) { // 左右扩充 for (int j = topBoundary; j <= bottomBoundary; j++) { result[j][leftBoundary - 1] = result[j][leftBoundary + (2 * i)]; result[j][rightBoundary + 1] = result[j][rightBoundary - (2 * i)]; } leftBoundary--; rightBoundary++; // 上下扩充 for (int j = leftBoundary; j <= rightBoundary; j++) { result[topBoundary - 1][j] = result[topBoundary + (2 * i)][j]; result[bottomBoundary + 1][j] = result[bottomBoundary - (2 * i)][j]; } topBoundary--; bottomBoundary++; } for (char[] chars : result) { for (char aChar : chars) { System.out.print(aChar); } System.out.println(); } System.out.println(); } }