//啤酒2元1瓶,4个瓶盖可换1瓶,2个空瓶也可换1瓶。请问10元能喝到几瓶啤酒

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/zhangmengleiblog/article/details/87918795

//啤酒2元1瓶,4个瓶盖可换1瓶,2个空瓶也可换1瓶。请问10元能喝到几瓶啤酒

-(void)beerWithMoney:(NSInteger)money Cap:(NSInteger)cap bottle:(NSInteger)bottle Count:(NSInteger)count{

    

    

    if(money<2&&cap<4&&bottle<2){

        NSLog(@"%ld",count);

    }

    

    if (money>=2) {

        [self beerWithMoney:money-2 Cap:cap+1 bottle:bottle+1 Count:count+1];

    }

    

    if (cap>=4) {

        [self beerWithMoney:money Cap:cap-4+1 bottle:bottle+1 Count:count+1];

    }

    

    if (bottle>=2) {

        [self beerWithMoney:money Cap:cap+1 bottle:bottle-2+1 Count:count+1];

    }

}

展开阅读全文

没有更多推荐了,返回首页