网易互娱笔试9.5
第一题
实现Sql,就是取同一个name有多个id的name总和。
select count(name) as cnt
select count(name) as cnt from( select name from database a group by name HAVING count(DISTINCT id)>=2 );;
第二题
动画刷新,思路是用二维数组记录每次移动结果,和上一次移动计算位置移动,并计数,然后不断循环移动,直到从屏幕上走开,结束
import java.util.*; public class Main { public static void main(final String[] args) { final Scanner in = new Scanner(System.in); final int num = in.nextInt(); for(int i=0;i<num;i++){ final int w = in.nextInt(); final int h = in.nextInt(); char[][] init = new char[w][h]; for (int j = 0; j < h; j++) { final String s = in.next(); for (int k = 0; k < w; k++) { init[j][k] = s.charAt(k); } } final int sizex = in.nextInt(); final int sizey = in.nextInt(); final char[][] profile = new char[sizex][sizey]; for (int j = 0; j < sizey; j++) { final String s = in.next(); for (int k = 0; k < sizex; k++) { profile[j][k] = s.charAt(k); } } int x1 = in.nextInt(); int y1 = in.nextInt(); final int xs = in.nextInt(); final int ys = in.nextInt(); int res = 0; while (!isFin(x1, y1, w, h, sizex, sizey)) { char[][] mat = deal(x1, y1, w, h, sizex, sizey, profile); res += compare(h,w,init,mat); init = mat; x1 += ys; y1 += xs; } System.out.println(res); } } public static boolean isFin(final int x1,final int y1,final int w,final int h,final int sizex, final int sizey){ //左上角 1 1 for(int i=0;i<sizex;i++){ for(int j=0;j<sizey;j++){ if(((x1+i)>=1 && (y1+j)>=1) && ((x1+i)<=h && (y1+j)<=w)){ return false; } } } return true; } public static char[][] deal(final int x1,final int y1,final int w,final int h,final int sizex, final int sizey, final char[][] profile){ char[][] init = new char[w][h]; for (int j = 0; j < h; j++) { for (int k = 0; k < w; k++) { init[j][k]='.'; } } for(int i=0;i<sizex;i++){ for(int j=0;j<sizey;j++){ if(((x1+i)>=1 && (y1+j)>=1) && ((x1+i)<=h && (y1+j)<=w)){ init[x1+i-1][y1+j-1] = profile[i][j]; } } } return init; } public static int compare(int h, int w, char[][] init, char[][] mat){ int res = 0; for (int j = 0; j < h; j++) { for (int k = 0; k < w; k++) { if(init[j][k]!=mat[j][k]){ res++; } } } return res; } }