五子棋_电话号码
五子棋
import java.util.*; public class Main { //上下左右...八个方位!!!! static int[][] direction = {{0, 1}, {0, - 1}, {1, 0}, { - 1, 0}, {1, 1}, {1, - 1}, { - 1, 1}, { - 1, - 1}}; public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (sc.hasNext()) { Character[][] map = new Character[20][20]; for (int i = 0; i < 20; i ++ ) { String s = sc.next(); for (int j = 0; j < 20; j ++ ) { map[i][j] = s.charAt(j); } } if(check(map)) System.out.println("Yes"); else System.out.println("No"); } } public static boolean check(Character[][] map) { for (int i = 0; i < 20; i ++ ) { for (int j = 0; j < 20; j ++ ) { if(map[i][j] == '*' || map[i][j] == '+') { for (int k = 0; k < 8; k ++ ) { int count = 1; int x = i + direction[k][0]; int y = j + direction[k][1]; while (x >= 0 && x < 20 && y >= 0 && y < 20 && map[x][y] == map[i][j]) { count ++ ; x += direction[k][0]; y += direction[k][1]; } if(count == 5) return true; } } } } return false; } }
电话号码
import java.util.*; public class Main{ public static void main(String[] args){ String symbol="ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"; String number="222333444555666777788899991234567890"; //这里用两张表进行查询! Scanner scanner=new Scanner(System.in); while(scanner.hasNext()){ int n=scanner.nextInt(); ArrayList<String> arrayList=new ArrayList<String>(); for(int i=0;i<n;i++){ String str=scanner.next(); str=str.replace("-",""); String result=""; for(int j=0;j<7;j++){ //采用字符串拼接,开销大! result+=number.charAt(symbol.indexOf(str.charAt(j)+"")); } result=result.substring(0,3)+"-"+result.substring(3,7); if(!arrayList.contains(result)) //去重! arrayList.add(result); } Collections.sort(arrayList);//集合排序!! Collections.sort() for(int j=0;j<arrayList.size();j++){ System.out.println(arrayList.get(j)); } System.out.println(); } } }#笔试#