package huawei; import java.util.Scanner; public class 约瑟夫环 {
private static class Node
{
public int num;
public Node next;
public Node(int n)
{
num=n;
} } public static String getOutString(int len, String str, int m)
{
String ans="";
String s[]=new String[len];
int n[]=new int[len];
s=str.split(",");
for(int i=0;i<len;i++)
{
n[i]=Integer.parseInt(s[i]);
// System.out.println(n[i]); }
//建立循环链表
Node node=new Node(n[0]);
Node header=node;
for(int i=1;i<len;i++)
{
node.next=new Node(n[i]);
node=node.next; }
//循环输出
node.next=header;
node=header;
System.out.println(node.num); while(node.next!=node)
{ for(int i=0;i<m-2;i++)
{
node=node.next;
}
// System.out.println(node.next.num);
ans+=node.next.num;
m=node.next.num;
node.next=node.next.next;
node=node.next; } //System.out.println(node.num); return ans+node.num; } public static void main(String[] args)
{
//Scanner s=new Scanner(System.in);
// System.out.println("请输入人的个数");
// int count=s.nextInt();
System.out.println(getOutString(4, "3,1,2,4", 7)); } }