[백준 1025번 C/C++] 제곱수 찾기
[백준 1025번 C/C++] 제곱수 찾기
해결전략
정답 코드
#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>
using namespace std;
int n, m;
int answer = -1;
bool flag = false;
int arr[10][10];
bool isSqureNum(int n)
{
int root = (int)sqrt(n);
if (root * root == n)
return true;
return false;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> n >> m;
string tmp = "";
for (int i = 1; i <= n; i++) {
cin >> tmp;
for (int j = 1; j <= m; j++) {
arr[i][j] = (int)tmp[j - 1] - 48;
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
for (int x = -n; x < n; x++) { // 행의 등차
for (int y = -m; y < m; y++) // 열의 등차
{
if (x == 0 && y == 0) continue;
int a = i, b = j;
int now = 0;
while (a > 0 && a <= n && b > 0 && b <= m)
{
now *= 10;
now += arr[a][b];
if (isSqureNum(now)) answer = max(answer, now);
a += x;
b += y;
}
if (isSqureNum(now)) answer = max(answer, now);
}
}
}
}
cout << answer << endl;
}
'⭐ 코딩테스트 > 백준' 카테고리의 다른 글
[백준 16946번 C/C++] 벽 부수고 이동하기 4 (1) | 2024.01.31 |
---|---|
[백준 17387번 C/C++] 선분 교차 2 (0) | 2024.01.30 |
[백준 17404번 C/C++] RGB거리 2 (1) | 2024.01.26 |
[백준 15824번 C/C++] 너 봄에는 캡사이신이 맛있단다 (0) | 2024.01.25 |
[백준 1019번 C/C++] 책 페이지 (0) | 2024.01.24 |
댓글
이 글 공유하기
다른 글
-
[백준 16946번 C/C++] 벽 부수고 이동하기 4
[백준 16946번 C/C++] 벽 부수고 이동하기 4
2024.01.31 -
[백준 17387번 C/C++] 선분 교차 2
[백준 17387번 C/C++] 선분 교차 2
2024.01.30 -
[백준 17404번 C/C++] RGB거리 2
[백준 17404번 C/C++] RGB거리 2
2024.01.26 -
[백준 15824번 C/C++] 너 봄에는 캡사이신이 맛있단다
[백준 15824번 C/C++] 너 봄에는 캡사이신이 맛있단다
2024.01.25