-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCodeAnalysis.java
More file actions
76 lines (56 loc) · 1.48 KB
/
CodeAnalysis.java
File metadata and controls
76 lines (56 loc) · 1.48 KB
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
package programming_contest_problems;
import java.util.*;
import java.io.*;
public class CodeAnalysis {
public static String [] arr;
public static void main(String [] args)
{
Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
int iter = in.nextInt();
int numOfInst = 0;
for (int i= 0; i< iter; i++ )
{
numOfInst = in.nextInt();
in.nextLine();
arr = new String [numOfInst];
for (int j = 0; j < numOfInst; j++)
{
arr[j] = in.nextLine();
}
recurse(arr, 1);
for (int h = 0; h < arr.length; h++)
{
String bool;
if (arr[h].compareTo("x") ==0){bool= "yes";}else{bool = "no";}
System.out.println("step " + h + " "+ bool);
}
}
}
public static void recurse(String [] arr, int instNumber)
{
int instToGo;
if (arr[instNumber-1].compareTo("x")!=0)
{
char test = Character.toUpperCase(arr[instNumber-1].charAt(0));
if (Character.compare('G', test) ==0)
{
instToGo = Integer.parseInt(arr[instNumber-1].split(" ")[1]);
arr[instNumber-1] = "x";
recurse(arr, instToGo);
}
if (Character.compare('C', test) ==0)
{
instToGo = Integer.parseInt(arr[instNumber-1].split(" ")[1]);
System.out.println("step no " + instToGo);
arr[instNumber-1] = "x";
recurse(arr, instNumber+1);
recurse(arr, instToGo);
}
if (Character.compare('N', test) ==0)
{
arr[instNumber-1] = "x";
recurse(arr, instNumber+1);
}
}
}
}