有多少面试可以重来

0001 问 50的阶乘末尾有多少个0?
解析,这个问题的实质是,问从1-50中间,有多少个5. 因为2是很充足的。
1相当于0个5, 5相当于1个5, 10相当于1个5,25相当于2个5 。。。。

/**
 * Created by yuan on 2017/2/12.
 */
public class GiveMe5 {

    private static int count_zero(int num){
        int cnt = 0;
        int i = 5;
        while((num/i) >= 1){
            cnt += num/i;
            i *= 5; 
        }

        return cnt;
    }
    public static void main(String[] args) {
        int  c = count_zero(50);
        System.out.println(c);
    }
}

运行结果是 12


0002 问 2块钱买一瓶啤酒,3个空瓶子换一个啤酒,现在有10块钱,能喝多少最多?(也看酒量)

直接编程

/**
 * Created by yuan on 2017/2/12.
 */
public class CountBeer {

    private static int get_beer(int money){
        int empty_bottle = 0;
        int drink_cnt = 0;
        int price = 2;
        int replace_cnt = 3;

        drink_cnt = money/price;
        empty_bottle = money/price;

        while(empty_bottle>= replace_cnt){
            drink_cnt += empty_bottle/3;
            empty_bottle = empty_bottle/3 + empty_bottle%3;
        }

        return drink_cnt;


    }
    public static void main(String[] args) {
        int cnt = get_beer(10);

        System.out.println(cnt);
    }
}

运行结果是 7


0003 概率题, A公交车7分钟一趟, B公交车5分钟一趟, 小张去上班做A,B公交车都能到? 问,小张出门等到A或者B 随便一趟的概率是多少?
答案: 5*7 / (5+7) = 35/12 = 2.92


0004 概率题, 箱子里有15个球,黑,白,红各5个, 现在从中抓取3个。 请问,抓取到的3个球, 颜色都不相同的概率是多少?

答案:15*10*5 / (15*14*13) = 25/91


猜你喜欢

转载自blog.csdn.net/u012063703/article/details/55004954
今日推荐