Bowling Score Assistant: Difference between revisions

From programming_contest
Jump to navigation Jump to search
imported>Kmk21
m Kmk21 moved page Bowling score calculator to Bowling Score Assistant without leaving a redirect
imported>Kmk21
No edit summary
 
Line 26: Line 26:
         return score;
         return score;
     }
     }
[[Category:ncna2013]]
[[Category:ICPC Problems]]
[[Category:Case Work]]
[[Category:Algorithm Easy]]
[[Category:Implementation Easy]]

Latest revision as of 02:59, 2 June 2015

   private int score_calculator(ArrayList<Integer> arr){
       int index = 0;
       int rank=0;
       int score=0;
       int len = arr.size();
       while(index<len-2){
           rank=0;
           int first = arr.get(index);
           int second = arr.get(index+1);
           score+=first;
           if(first==10){
               rank=2;
               score+=arr.get(index+1)+arr.get(index+2);
               index++;
               continue;
           }else if(first+second==10){
               rank=1;
               score+=arr.get(index+2);
           }
           score+=second;
           index+=2;
       }
       if(rank==0){
           score+=arr.get(len-2)+arr.get(len-1);
       }
       return score;
   }