A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© xiong910627   /  2014-9-4 10:40  /  6771 人查看  /  40 人回复  /   6 人收藏 转载请遵从CC协议 禁止商业使用本文

感谢分享了
回复 使用道具 举报
    学习了
回复 使用道具 举报
chen_32768 发表于 2014-9-4 16:04
学习一下,我的测试题就是这个、

这个是基础测试吗。兄弟
回复 使用道具 举报
学习了 ,我的也是这个……
回复 使用道具 举报
顶顶顶顶顶顶
回复 使用道具 举报
学习下。。。。。。。
回复 使用道具 举报
来赞一个
回复 使用道具 举报
来赞一个
回复 使用道具 举报
谢谢分享,学习了
回复 使用道具 举报
赞一个学习了。
回复 使用道具 举报
楼主好厉害!
回复 使用道具 举报
正常用汉字很轻松就能解决,可用代码就很吃力。学习了。
回复 使用道具 举报
很厉害呀! 自己一开始完全不会做呢
回复 使用道具 举报
这题  感觉挺难得额
回复 使用道具 举报
风华正茂 来自手机 中级黑马 2015-8-14 12:14:16
35#
学习了,谢谢楼主分享
回复 使用道具 举报
测试试题啊。。。
回复 使用道具 举报
个人认为有些 部分没有必要,这样可以吗?
public class Test10 {
        public static void main(String[] args) {
                new Test10().tohere();
        }

    //创建一个集合,代表起始点.
    ArrayList<String> here = new ArrayList<String>();
    //创建一个集合,代表终点.
    ArrayList<String> there = new ArrayList<String>();
    //添加元素.
    public Test10()
    {
        here.add("Dog");
        here.add("cat");
        here.add("fish");
    }
   
    //定义一个方法,用来判断这三个动物之间关系.
    public boolean isSafe(ArrayList<String> al){
            if (al.contains("dog") && al.contains("cat")
                            || al.contains("cat") && al.contains("fish")){
                    return false;
        }
            return true;
    }

    //定义一个方法,将起点的元素送到终点.
    public void tohere() {
        String str = here.get(0);
        here.remove(str);
        if (isSafe(here)) {
            System.out.println("1农夫带着" + str + "去往对岸,这边还剩下" + here + ",对岸有" + there);
            toThere(str);
            }
                else{
                here.add(str);
                tohere();
            }
    }

    //定义一个方法,用来查看终点的元素.
    public void toThere(String s){                  
       // if(isSafe(there)){
                        there.add(s);
                        if(here.isEmpty()){
                                System.out.println("4农夫,"+there+"都被你带过来了");
                                return;
                        }

                        if(isSafe(there)){
                                System.out.println("2农夫回到原点,对岸有" + there);
                                tohere();
                        }
                        else{
                                String temp=there.get(0);
                                there.remove(temp);
                                System.out.println("3农夫带着"+temp+"回到原点,这边有" + here + ",对岸有" + there);
                                here.add(temp);
                                tohere();
                        }
//        }
//        else{
//                        there.remove(s);
//                        tohere();
//        }
    }
}
回复 使用道具 举报
..........................
回复 使用道具 举报
大牛啊                                 
回复 使用道具 举报
其实代码不难,难的是思路
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马