Problem Statement
The rules of scoring are as follows:
-0 defeats 1, 1 defeats 2, 2 defeats 3, 3 defeats 4, 4 defeats 5, and 5 defeats 0.
-Note that each number defeats exactly one other number.
-If you are the only person to pick your number, your "point-factor" is equal to the number of players, otherwise it is 1.
-You get a "victory" for every player that chooses a number which your number defeats. Victories are worth point-factor point(s) each.
-You "survive" if no other person picked the number that defeats yours. This is worth 1 point.
-If you do not survive, you lose 1 point.
-If you survive AND you pick the lowest number out of everyone (whether they survived or not) you earn an extra 10 points.
-If more than one person survives AND picks the lowest number, they each receive the 10 point bonus.
-At the end of a each round, no player can have negative total points. If your total points drop below zero, they are reset to zero again.
We repeat this process a number of times, and add up the points from each round.Players' scores are zero at the beginning of the first round.
Your task is to write a method for that will determine the final score of the game given the numbers that each player chooses every round. fingers contains all of the moves for each player throughout the game. Each element of fingers represents the moves a player makes for a round. For example, the third digit of element 0 is the number of fingers player 0 holds up in round three. The total number of rounds in the game is equal to the length of each element in fingers. You should return a
Definition
- Class:
- RPSVariant
- Method:
- finalScore
- Parameters:
- String[]
- Returns:
- int[]
- Method signature:
- int[] finalScore(String[] fingers)
- (be sure your method is public)
Constraints
- There will be between 2 and 10 elements in fingers, inclusive
- Each element of fingers will contain only digits (0-5, inclusive)
- Each element of fingers will be of equal length
- Each element of fingers will contain between 1 to 50 digits, inclusive
Examples
{"02301", "04545", "33343", "54321"}
Returns: { 48, 3, 21, 31 }
The scores after each round are: {0,0,1,9} {15,0,8,8} {26,1,19,19} {37,2,20,20} {48,3,21,31} Keep in mind that the total point may not go below 0.
{"3", "4", "1", "0"}
Returns: { 5, 0, 0, 15 }
{"11111", "22222", "33333", "44444", "55555"}
Returns: { 80, 20, 20, 20, 0 }
Every round, player 0 gets 1 point for surviving, 5 points for a victory over player 1, and 10 points for choosing the lowest number and surviving. Players 1 through 3 get 5 points every round for their victories over the players with the number one above theirs.
{"43024540", "53420154", "01235422", "24301300", "24351431"}
Returns: { 43, 33, 30, 22, 13 }
{"00000000000000000000000000000000000000000000000000", "11111111111111111111111111111111111111111111111111", "11111111111111111111111111111111111111111111111111", "11111111111111111111111111111111111111111111111111", "11111111111111111111111111111111111111111111111111", "11111111111111111111111111111111111111111111111111", "11111111111111111111111111111111111111111111111111", "11111111111111111111111111111111111111111111111111", "11111111111111111111111111111111111111111111111111", "11111111111111111111111111111111111111111111111111"}
Returns: { 5050, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
{"412051123423412501251304", "143200125230441205113024", "120412501230234124051034", "412302340342341432042314", "140124230412401234240430", "404302340234012402340455", "302324013020234234202511", "355501421021450234012434"}
Returns: { 110, 163, 167, 68, 121, 60, 106, 130 }
{"00000000000000000000000000000000000000000000000000", "11111111111111111111111111111111111111111111111111", "22222222222222222222222222222222222222222222222222", "33333333333333333333333333333333333333333333333333", "44444444444444444444444444444444444444444444444444", "55555555555555555555555555555555555555555555555555"}
Returns: { 250, 250, 250, 250, 250, 250 }
{"1", "3", "5"}
Returns: { 11, 1, 1 }
{"3", "4", "1", "0"}
Returns: { 5, 0, 0, 15 }
{"43024540", "53420154", "01235422", "24301300", "24351431"}
Returns: { 43, 33, 30, 22, 13 }
{"11111", "22222", "33333", "44444", "55555"}
Returns: { 80, 20, 20, 20, 0 }
{"152432451325423152431523154", "415243245132542315243152315", "541524324513254231524315231", "154152432451325423152431523", "315415243245132542315243152", "231541524324513254231524315"}
Returns: { 112, 142, 188, 167, 166, 120 }
{"105204320451325423152431523154", "415243204501320542315243152315", "504152432451032542301524315231", "154015243245132542315243152003", "315415243245132542315243152000", "203010541524324513254231524315"}
Returns: { 213, 103, 197, 133, 90, 163 }
{"152524451325423152431523154", "415142245132542315243152315", "521524324514254251523325231", "333152432451325422252431523", "152143554425341255243511423", "000000000000000000000000000", "152143554425341255243511423"}
Returns: { 120, 135, 187, 99, 15, 205, 15 }
{"01010101", "10101010", "01010101", "10101010"}
Returns: { 48, 49, 48, 49 }
{"012345012345", "123450123450", "234501234501", "345012345012", "450123450123", "501234501234", "000000000000", "222222222222", "333333333333", "555555555555"}
Returns: { 80, 80, 80, 80, 80, 80, 0, 12, 0, 12 }
{"40221003101015211510350121120520403243354134422135", "44135520224015452435114004045200124135420351141323", "15220010042432351424020552305551503114540011051324", "45005155020234020452504044334003545225542401221220", "41030013124033554503342104004504212034124430124431", "55500403113123435103232002350441031330015415042401", "14010454423053103213122203004235200435124303343405", "23410301142333033333122514545404413122043255304322", "34340044324355410515130425533441511024143213135021", "13243534244111203044155100143140412201030304351404"}
Returns: { 213, 243, 362, 412, 115, 356, 230, 148, 194, 248 }
{"33523221305114543323503235223325200314523511222131", "11144345412340334010012421412301521241411441310043", "21122040023441441135323122441504231050434100243354", "45535255344104555502002202121344213504441151434520", "02230242323041201032123310025400550334512115423423", "52250450543320354341244143010341214152543345122422", "04320523531142531304024502245535531420524333010421", "51243033343105113315505104054503553115322102223545", "30021044201033113542233552505243054033450314335325", "34011050201350102400014511414224225024155331523335"}
Returns: { 181, 290, 229, 260, 226, 182, 240, 240, 399, 266 }
{"0", "3", "5"}
Returns: { 0, 1, 4 }
{"0", "1", "2"}
Returns: { 14, 2, 0 }
{"02301", "04545", "33343", "54321"}
Returns: { 48, 3, 21, 31 }
{"43024540", "53420154", "01235422", "24301300", "24351431"}
Returns: { 43, 33, 30, 22, 13 }
{"15403213", "13542034", "43152345", "13421304", "12341254", "34150432"}
Returns: { 27, 26, 15, 18, 65, 64 }
{"2345432", "2222222", "3333333", "1234512", "1235123"}
Returns: { 16, 73, 6, 68, 41 }
{"0000", "0000", "0000", "0000"}
Returns: { 44, 44, 44, 44 }
{"0", "0", "0", "0", "0", "0"}
Returns: { 11, 11, 11, 11, 11, 11 }
{"032342453534525342445213451233524134531523415324", "315431254351234234235134324314235134232531245314", "244444444444444444444444444444444444444444444444", "412222222222222333333333333333334444444444442222", "512543232332423232324242314234132414324123142332", "321321332133333333333333333322222222222222223123", "421312312321312441243232131231241241241243342343", "423231324353423243423243534231423123132314253423", "524243243243423424524324242423423243244242532232", "234232415432153215321325413253123152315231532152"}
Returns: { 133, 303, 29, 189, 303, 214, 434, 279, 222, 292 }
{"00000", "00000", "11111"}
Returns: { 60, 60, 0 }
{"012345", "123450", "234501", "345012", "450123"}
Returns: { 56, 24, 24, 24, 0 }
{"11111", "12345", "23455", "23455", "53211"}
Returns: { 67, 48, 1, 1, 26 }
{"11111", "22222", "33333", "44444", "55555"}
Returns: { 80, 20, 20, 20, 0 }
{"12", "13", "24", "23"}
Returns: { 32, 13, 0, 0 }
{"234543", "222222", "234453", "444444"}
Returns: { 13, 82, 13, 4 }
{"2", "2", "2", "2", "1"}
Returns: { 0, 0, 0, 0, 31 }
{"43024540", "53420154", "01235422", "24301300", "24351431"}
Returns: { 43, 33, 30, 22, 13 }
{"05050505050505050505", "50505050505050505050", "20345232023430234012", "11111111111111111111", "00000000000000000000", "55555555555555555555"}
Returns: { 30, 29, 41, 16, 1, 58 }
{"22255", "11153", "32145"}
Returns: { 1, 53, 30 }
{"0123450", "0123450", "2222222", "5555222", "5040555"}
Returns: { 12, 12, 45, 37, 28 }
{"01", "00", "00", "00"}
Returns: { 10, 23, 23, 23 }
{"35030210353021320430", "11111111111111111111", "00000000000000000000", "50505050505050505050", "05050505050505050505", "44444444443333222211"}
Returns: { 33, 28, 4, 140, 118, 78 }