菜鸟程序员


私信TA

用户名:15026749469

访问量:27271

签 名:

。。。

等  级
排  名 390
经  验 4972
参赛次数 1
文章发表 65
年  龄 0
在职情况 在职
学  校
专  业

  自我简介:

TA的其他文章

import java.util.Scanner;

public class Main
{
	public static void main(String[] args)
	{
		int n;
		Scanner S = new Scanner(System.in);
		n = S.nextInt();

		Createlist  A = new Createlist();
        A.setlen(n);
		A.create();
		A.traverse();
	}
}

class Child
{
	int n;
	Child next=null;
	public Child(int n )
	{
       this.n = n;
	}
}

class Createlist
{
	Child head = null;
	Child tem = null;
	int n=0;
	public void setlen(int n)
	{
		this.n=n;
	}
    
	public void create()
	{
		for(int i=0;i<n;++i)
		{
			if(i==0)
			{
				Child pnew =new Child(i+1);
                this.head = pnew;
			    this.tem= pnew;
			}
			else
			{
				Child pnew =new Child(i+1);
			    tem.next= pnew;
				tem = pnew;
			}
		}
	    tem.next = head;
	}

	public void traverse()
	{
		Child T = this.head;
		while(n != 1)
		{
			for(int j =1;j<2;++j)
		    {
               T = T.next;
		     }

		    T.next=T.next.next;
		    T = T.next;         
			 --n;
		}      
		System.out.println(T.n);
	}
}

解题思路:

注意事项:

参考代码:

 

0.0分

0 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区