chuoidaosol1
quoc14
c_cpp
a year ago
1.7 kB
7
Indexable
caidat
// Online C++ compiler to run C++ program online
#include <iostream>
using namespace std;
char a[105][105];
int ans;
int tmp, x, y;
void lan(int i, int j) {
// lan ngang
tmp = 1;
x = j -1;
y = j + 1;
if (a[i][j] == a[i][x] && x >= 1) {
x--;
tmp++;
}
if (a[i][j] == a[i][y] && y <= 100) {
y++;
tmp++;
}
while (x >= 1 && y <= 100) {
if (a[i][x] == a[i][y]) {
tmp += 2;
x--;
y++;
if (tmp > ans) ans = tmp;
}
else {
break;
}
}
if (tmp > ans) ans = tmp;
// lan doc
tmp = 1;
x = i -1;
y = i + 1;
if (a[i][j] == a[x][j] && x >= 1) {
x--;
tmp++;
}
if (a[i][j] == a[y][j] && y <= 100) {
y++;
tmp++;
}
while (x >= 1 && y <= 100) {
if (a[x][j] == a[y][j]) {
x--;
y++;
tmp += 2;
if (tmp > ans) ans = tmp;
}
else {
break;
}
}
}
void solve(int testcase) {
for (int i = 1; i <= 100; i++) {
for (int j = 1; j <= 100; j++) {
cin >> a[i][j];
}
}
ans = 1;
for (int i = 2; i <= 99; i++) {
for (int j = 2; j <= 99; j++) {
lan(i, j);
}
}
cout << "#" << testcase << " " << ans << endl;
}
int main() {
// Write C++ code here
freopen("Text.txt", "r", stdin);
for (int i = 1; i <= 10; i++) {
int n; cin >> n;
solve(n);
}
return 0;
}Editor is loading...
Leave a Comment