File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import java .io .BufferedReader ;
2+ import java .io .IOException ;
3+ import java .io .InputStreamReader ;
4+ import java .util .*;
5+
6+
7+ public class boj_1025_제곱수찾기 {
8+
9+ static int n , m ;
10+ static int [][] arr ;
11+ static int result = -1 ;
12+
13+ public static void main (String [] args ) throws IOException {
14+ BufferedReader br = new BufferedReader (new InputStreamReader (System .in ));
15+ String [] s = br .readLine ().split (" " );
16+ n = Integer .parseInt (s [0 ]);
17+ m = Integer .parseInt (s [1 ]);
18+
19+ arr = new int [10 ][10 ];
20+
21+ for (int i = 0 ; i < n ; i ++) {
22+ String s1 = br .readLine ();
23+ for (int j = 0 ; j < m ; j ++) {
24+ arr [i ][j ] = Integer .parseInt (String .valueOf (s1 .charAt (j )));
25+ }
26+ }
27+ for (int i = 0 ; i < n ; ++i )
28+ for (int j = 0 ; j < m ; ++j )
29+ for (int mi = -n ; mi < n ; ++mi )
30+ for (int mj = -m ; mj < m ; ++mj )
31+ {
32+ if (mi == 0 && mj == 0 ) { // 둘다 움직이지 않을 때
33+ continue ;
34+ }
35+
36+ int t = 0 ;
37+ int newI = i ;
38+ int newJ = j ;
39+ while (newI >= 0 && newI < n && newJ >= 0 && newJ < m ) // 위치가 0>= && <범위를 설정해줍니다.
40+ {
41+ t = 10 * t + arr [newI ][newJ ]; // 기존에 담긴 숫자가 있다면 *10해주고 더해줍니다.
42+ if (Math .abs (Math .sqrt (t ) - (int )Math .sqrt (t )) < 1e-10 ){ // 완전 제곱수인지 판별합니다.
43+ result = Math .max (result , t );
44+ }
45+ newI += mi ;
46+ newJ += mj ;
47+ }
48+
49+ }
50+ System .out .println (result );
51+ }
52+ }
You can’t perform that action at this time.
0 commit comments