行业知识
美团2024届秋招笔试第一场编程真题——小美的好矩阵
2026-12-03 17:30:17
来源:互联网转载
小index.php/tags-41973.html" >���定义一个矩阵是好矩阵,当且仅当该矩阵满足:
()- 矩阵仅由’A’、‘B’、'C’三种字符组成。且三种字符都出现过。
- 矩阵相邻的字符都不相等。
现在给定一个n∗m的矩阵,小美想知道有多少个3*3的子矩阵是好矩阵,你能帮帮她吗?
输入描述:
()第一行输入两个整数n,m,代表矩阵的行数和列数。
接下来的n行,每行输入一个仅包含大写字母的长度为m的字符串。
1 public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); int m = scanner.nextInt(); char[][] matrix = new char[n][m]; for (int i = 0; i y && matrix[i][j] == matrix[i][j - 1]) { return false; } } } return count[0] > 0 && count[1] > 0 && count[2] > 0; }}
上一篇:tiny服务器怎么看后台?