蒟蒻求助 二十分
查看原帖
蒟蒻求助 二十分
981981
little_whitezzz楼主2024/3/11 18:26
import java.io.BufferedInputStream;
import java.util.Scanner;

public class Main {
    static int N = 110;
    static char[][] bs = new char[N][N];
    static int R, C, K;

    public static void main(String[] args) {
        Scanner sc = new Scanner(new BufferedInputStream(System.in));
        R = sc.nextInt();
        C = sc.nextInt();
        K = sc.nextInt();
        int cnt = 0;
        sc.nextLine();
        for (int i = 1; i <= R; i++) {
            String str = sc.nextLine();
            for (int j = 0; j < str.length(); j++)
                bs[i][j] = str.charAt(j);
        }
        //处理横向
        for (int i = 1; i <= R; i++)
            for (int j = 0; j < C; j++) {
                int mark = j;
                if (bs[i][j] == '.') {
                    while (j < C && bs[i][j] == '.') {
                        if (j - mark + 1 == K) {
                            cnt++;
                            break;
                        }
                        j ++;
                    }
                    j --;
                }
            }
        //处理竖直方向
        for (int i = 0; i < C; i++)
            for (int j = 1; j <= R; j++) {
                int mark = j;
                if (bs[j][i] == '.') {
                    while (j <= R && bs[j][i] == '.') {
                        if (j - mark + 1 == K) {
                            cnt++;
                            break;
                        }
                        j++;
                    }
                    j --;
                }
            }
        if(K == 1)
            cnt /= 2;
        System.out.print(cnt);
    }
}

2024/3/11 18:26
加载中...