码个code给bangbang9814

天天码code,预防老年痴呆!把25人推广成N,把7推广成M,下面是个JAVA code:

public void func(int n, int m) {
        ArrayList<String> people = new ArrayList<String>();
        for (int i = 1; i <= n; i++)
        {
            people.add(new String(String.valueOf(i)));
        }
       
        int ct = 1;
        int index = 0;
       
        while(people.size() > 1)
        {
            if (ct%m==0)
            {
                index = index%people.size();
                people.remove(index);
                index --;
            }
            ct++;
            index++;
        }   
        System.out.println("Last Person: " + people.get(0).toString());
    }

所有跟帖: 

大谢!回头让儿子看看是否能看懂。你真的神通广大哦。 -bangbang9814- 给 bangbang9814 发送悄悄话 (0 bytes) () 06/19/2012 postreply 17:59:15

天天码code,预防老年痴呆? 老年痴呆天天码code, -奉旨灌水- 给 奉旨灌水 发送悄悄话 奉旨灌水 的博客首页 (0 bytes) () 06/19/2012 postreply 18:28:38

哈哈哈哈, -柯西- 给 柯西 发送悄悄话 柯西 的博客首页 (58 bytes) () 06/19/2012 postreply 19:40:17

天天找Defect,也预防老年痴呆。。。 -淘淘爸- 给 淘淘爸 发送悄悄话 (278 bytes) () 06/19/2012 postreply 22:28:13

带入几组不同的N,M,拿去RUN一下就知道了。 -文学村民- 给 文学村民 发送悄悄话 (0 bytes) () 06/20/2012 postreply 08:24:13

请您先登陆,再发跟帖!