码迷,mamicode.com
首页 > 系统相关 > 详细

VMware coding Challenge: Coin Toss Betting

时间:2015-03-07 06:14:58      阅读:164      评论:0      收藏:0      [点我收藏+]

标签:

技术分享

 1     static int CoinTossEndAmount(int betAmount, String coinTossResults) {
 2         if (betAmount <=0 || coinTossResults.length() == 0) return betAmount;
 3         long Amount = betAmount;
 4         long onebet = 1;
 5         for (int i=0; i<coinTossResults.length(); i++) {
 6             if (coinTossResults.charAt(i) == ‘H‘) {
 7                 Amount += onebet;
 8                 onebet *= 2;
 9             }
10             else {
11                 Amount -= onebet;
12                 onebet /= 2;
13             }
14             if (Amount < onebet) return 0;
15             if (onebet < 1) onebet = 1;
16         }
17         return (int)Amount;
18     }

 

VMware coding Challenge: Coin Toss Betting

标签:

原文地址:http://www.cnblogs.com/EdwardLiu/p/4319661.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!