-
Notifications
You must be signed in to change notification settings - Fork 0
/
exit point of matrix
81 lines (62 loc) · 1.4 KB
/
exit point of matrix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws Exception {
Scanner scn=new Scanner(System.in);
int n=scn.nextInt();
int m=scn.nextInt();
int[][] arr=new int[n][m];
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
arr[i][j]=scn.nextInt();
}
}
int d=0;
int i=0;
int j=0;
while(true)
{
d=(d+arr[i][j])%4;
if(d==0)
{
j++;
}
else if(d==1)
{
i++;
}
else if(d==2)
{
j--;
}
else if(d==3)
{
i--;
}
if(i<0)
{
i++;
break;
}
else if(j<0)
{
j++;
break;
}
else if(i>=n)
{
i--;
break;
}
else if(j>=m)
{
j--;
break;
}
}
System.out.println(i);
System.out.println(j);
}
}