APS/SWEA
1216. [S/W 문제해결 기본] 3일차 - 회문2
문래동까마귀
2021. 11. 19. 01:44
https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV14Rq5aABUCFAYi
SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
swexpertacademy.com
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <string>
//#include <fstream>
using namespace std;
char map[101][101];
int direct[2][2] = {
0,1, //우측
1,0 //아래
};
int MAX;
vector<char>str;
void Right_check(int y, int x, int len) {
int flag = 0;
str.push_back(map[y][x]);
if (len!=1) {
for (int j = 0; j < len / 2; j++) {
if (str[j] != str[len - 1 - j]) {
flag = 1;
break;
}
}
if (flag == 0) {
if (len > MAX)
MAX = len;
}
}
int dy = y + direct[0][0];
int dx = x + direct[0][1];
if (dy < 0 || dx < 0 || dy >= 100 || dx >= 100)
return;
Right_check(dy, dx, len+=1);
str.pop_back();
}
void down_check(int y, int x, int len) {
int flag = 0;
str.push_back(map[y][x]);
if (len != 1) {
for (int j = 0; j < len / 2; j++) {
if (str[j] != str[len - 1 - j]) {
flag = 1;
break;
}
}
if (flag == 0) {
if (len > MAX)
MAX = len;
}
}
int dy = y + direct[1][0];
int dx = x + direct[1][1];
if (dy < 0 || dx < 0 || dy >= 100 || dx >= 100)
return;
down_check(dy, dx, len+=1);
str.pop_back();
}
int main() {
//ofstream fout;
//fout.open("a.txt");
//ifstream fin;
//fin.open("input.txt");
int test_case;
for (test_case = 1; test_case <= 10; ++test_case) {
int T;
cin >> T;
MAX = 0;
for (int x = 0; x < 100; x++) {
cin >> map[x];
}
for (int y = 0; y < 100; y++) {
for (int x = 0; x < 100; x++) {
str.clear();
Right_check(y, x, 1);
str.clear();
down_check(y, x, 1);
}
}
cout << "#" << test_case << " " << MAX << endl;
}
//fin.close();
//fout.close();
return 0;
}