-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathYouXi.java
More file actions
35 lines (28 loc) · 1018 Bytes
/
Copy pathYouXi.java
File metadata and controls
35 lines (28 loc) · 1018 Bytes
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
package com.example;
import java.util.LinkedList;
public class YouXi {
public static int removeNM(int n, int m) {
LinkedList ll = new LinkedList();
for (int i = 0; i < n; i++)
ll.add(new Integer(i + 1));
int removed = -1;
while (ll.size() > 1) {
removed = (removed + m) % ll.size();
ll.remove(removed--);
for (int i = 0; i < ll.size(); i++){
System.out.print(" ");
System.out.print(ll.get(i));
}
System.out.println(" removed:"+removed);
}
return ((Integer) ll.get(0)).intValue();
}
public static void main(String[] args) {
System.out.println(removeNM(50, 3));
System.out.println(2/50);
System.out.println(3%49);
// LinkedList ll = new LinkedList();
// for (int i = 0; i < n; i++)
// ll.add(new Integer(i + 1));
}
}