20 分蒟蒻求调
查看原帖
20 分蒟蒻求调
470348
oddy楼主2022/2/19 14:11

这是代码:

#include <iostream>
#include <algorithm>

int r, c, k;
char s[100][101];

void input() {
    std::cin >> r >> c >> k;
    for(int i = 0; i < r; i++)
        std::cin >> s[i];
}

void work() {
    int cnt = 0, ans = 0;
    for(int i = 0; i < r; i++)
        for(int j = 0; j < c; j++) {
            if(s[i][j] == '#') ans += std::max(0, cnt - k + 1), cnt = 0;
            else cnt++;
        }
    if(k != 1) for(int i = 0; i < c; i++)
        for(int j = 0; j < r; j++) {
            if(s[i][j] == '#') ans += std::max(0, cnt - k + 1), cnt = 0;
            else cnt++;
        }
    std::cout << ans << '\n';
}

int main() {
    input();
    work();
    return 0;
}

百思不得其解,请各位大佬帮我看看。

2022/2/19 14:11
加载中...