五子棋_电话号码

五子棋

五子棋

image-20220520161922828

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;
    }
}

电话号码

电话号码

image-20220523132702884

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();
        }
    }
}
#笔试#
全部评论
包含的全面学习很多
点赞 回复 分享
发布于 2022-08-27 13:08 河南

相关推荐

点赞 评论 收藏
分享
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务