-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathlab5.java
More file actions
59 lines (46 loc) · 1.33 KB
/
lab5.java
File metadata and controls
59 lines (46 loc) · 1.33 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
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class circulargame {
public static class Node {
Node link ;
int data ;
Node(int number , Node connect){
data = number ;
link = connect ;
}
Node(int number){
data = number;
}
Node(){
link = null ;
}
}
public static void game() throws IOException{
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
int input = Integer.parseInt(reader.readLine());
int i = 0;
while (i<input){
Node y =new Node(1);
Node front =y;
int number = Integer.parseInt(reader.readLine());
for (int j=2 ; j<=number ; j++){
Node x =new Node(j);
y.link = x;
y =x;
}
y.link = front;
Node z = front;
while((z.link).link != z){
Node h = z.link;
z.link = h.link;
z = z.link;
}
System.out.println(z.data);
i++;
}
}
public static void main(String[] args) throws IOException{
game();
}
}