Problem Statement
- Whenever Hero plays a card with a '+', the counter is incremented. (I.e., its value is increased by 1.)
- Whenever Hero plays a card with a digit, he gets some (possibly zero) penalty points. The number of penalty points is calculated as abs(C - D), where C is the current value of the counter and D is the digit on the card.
Definition
- Class:
- Plusonegame
- Method:
- getorder
- Parameters:
- String
- Returns:
- String
- Method signature:
- String getorder(String s)
- (be sure your method is public)
Notes
- Let S and T be two different but equally long strings, and let i be the smallest index such that S[i] and T[i] differ. We say that S is lexicographically smaller than T if the character S[i] has a smaller ASCII value than the character T[i].
- The ASCII value of the '+' character is smaller than the ASCII values of digits.
Constraints
- s will contain between 1 and 50 characters, inclusive.
- Each character in s will be either '+' or digit('0' - '9').
Examples
"1++"
Returns: "+1+"
Hero should increment the counter to 1, then play the card '1' for 0 penalty points, and then increment the counter again.
"549"
Returns: "459"
Each of the six possible permutations of these cards leads to the same result: Hero will receive 4+5+9 = 18 penalty points. The string "459" is the lexicographically smallest of the six possible strings.
"++++++"
Returns: "++++++"
"+++++2+"
Returns: "++2++++"
"++++4++++200++2++1+6++++++"
Returns: "00+1+22++4++6+++++++++++++"
"++11199999"
Returns: "+111+99999"
"++48++++7+5+++4++2+++7+829+3+++4+++7++++++"
Returns: "++22+3+444+5++777+88+9++++++++++++++++++++"
"608+28590++8340689++8+93+8+7+6+4077+067420"
Returns: "000000++22+33+444+5+6666+7777+888888+999++"
"0+7735++1263020485214+19449+07887+++++++1+"
Returns: "0000+1111+222+33+4444+55+6+7777+888+99++++"
"8+892537++08618+2880856++282594+819692+++115228729"
Returns: "00+1111+22222222+3+4+5555+666+77+8888888888+99999+"
"+++5++++++++++++7+++++"
Returns: "+++++5++7+++++++++++++"
"6++++++++++++++++++++++++++++2++++++++++++++"
Returns: "++2++++6++++++++++++++++++++++++++++++++++++"
"32851++4+++237833223++7++++13++5+2+4+0+05++650"
Returns: "000+11+22222+333333+44+5555+6+77+88+++++++++++"
"+++++++++++++++++++++++++++++++++++++++++++++"
Returns: "+++++++++++++++++++++++++++++++++++++++++++++"
"5+0+++++13+4319++8709+7+8+10+4+1++236++6796++++"
Returns: "000+1111+2+333+44+5+666+777+88+999+++++++++++++"
"+++++++5+++++++++++++++++++++++++++++++++9+4+++6++"
Returns: "++++4+5+6+++9+++++++++++++++++++++++++++++++++++++"
"+++++++++++++3+++++++++9++570+++++++++5+3+++7++++"
Returns: "0+++33++55++77++9++++++++++++++++++++++++++++++++"
"31534+98+5874++60949+4+0+9++784+5+82+955++"
Returns: "00+1+2+33+44444+55555+6+77+8888+99999+++++"
"27"
Returns: "27"
"30587399881469"
Returns: "01334567888999"
"+73689+3748+++1652362++9++++361+662505+6043+"
Returns: "00+11+222+33333+44+555+6666666+77+88+99+++++"
"+++++++++"
Returns: "+++++++++"
"+80133++92"
Returns: "0+1+2+3389"
"+188+31+5+9804+9578+4++59"
Returns: "0+11++3+44+555++7+8888999"
"+04+++++++37++3++3++8++4++++8++++96++++"
Returns: "0+++333+44++6+7+88+9+++++++++++++++++++"
"++++++++1++1+++++++++++++++++"
Returns: "+11++++++++++++++++++++++++++"
"+++++632"
Returns: "++2+3++6"
"1192+29368632258++00980577710590752466935580+7"
Returns: "000000+111+22222+333+4555555666677777888899999"
"9330686+15+4"
Returns: "0+1+33456689"
"0+1226694+19+565+64++31816++9+254202++"
Returns: "00+1111+22222+3+444+555+66666++8+999++"
"54+++2+++++++++++++9++++++7+++++2++8+8+++65+7+++"
Returns: "++22++4+55+6+77+88+9++++++++++++++++++++++++++++"
"13+++7++++++8+++++++++41+++4"
Returns: "+11++3+44+++7+8+++++++++++++"
"+70+1335708+0+8+32+81++"
Returns: "000+11+2+333++5++77+888"
"748379+56+0836++"
Returns: "0+++33+456677889"
"2+94+7+++79+9++34+0098+09+83147952+81306088940+837"
Returns: "000000+11+22+3333+4444+5+6+7777+888888+9999999++++"
"+++++36++++++0++68+4+++++9++++6+880++56+4+8++++++3"
Returns: "00+++33+44+5+6666++8888+9+++++++++++++++++++++++++"
"4+7++12+1++067+5475+88++++50++47+7+0++51+7++9268+"
Returns: "000+111+22++444+5555+66+777777+888+9+++++++++++++"
"++++"
Returns: "++++"
"6++1+7+++483+++3++60+93+1+4++70+2"
Returns: "00+11+2+333+44++66+77+8+9++++++++"
"++71+++0+++6+++++7+999++++8++8"
Returns: "0+1+++++6+77+88+999+++++++++++"
"++0++++++++++++++++++++++++++++++++++++++"
Returns: "0++++++++++++++++++++++++++++++++++++++++"
"+++7+++++++5+++++++0++++++++++++"
Returns: "0+++++5++7++++++++++++++++++++++"
"+++50+6++8++++++2262+080+30+0+"
Returns: "00000++222+3++5+66++88++++++++"
"155+++22+++87+0+9"
Returns: "0+1+22+++55++7+89"
"9512373083295463981135927353217918782810171111"
Returns: "0011111111111222223333333455556777778888899999"
"1253982+804+540307508594+425165929368871512074"
Returns: "00000+1111+22222+33344444555555566777888889999"
"+++4+90+3+3+99+3+++6+++91+++++++++67+++2+"
Returns: "0+1+2+333+4++66+7++9999++++++++++++++++++"
"29+35085593296+167525143591"
Returns: "0+111+222333455555566789999"
"2087333+18829+0+25+29877530543+4+4"
Returns: "000+1+2222+33333+444+555+777888899"
"4833118393+30+117+8++85320218++899938904+80+190703"
Returns: "000000+111111+22+33333333+44+5++77+88888888+999999"
"071006151193857748+15820543188512"
Returns: "0000+1111111223344555556777888889"
"6++3+23++18+9+7++59+3+++47+43++280"
Returns: "0+1+22+3333+44+5+6+77+88+99+++++++"
"+++46++++++++++"
Returns: "++++4++6+++++++"
"++++++1++++++0+++++++++++++"
Returns: "0+1++++++++++++++++++++++++"
"+++++++++++++++++++++6++++++++++5++9+++++++++9+"
Returns: "+++++5+6+++99++++++++++++++++++++++++++++++++++"
"382++5++269+++740+2+4+++4+++++7+++4++9++++++++1+++"
Returns: "0+1+222+3+4444+5+6+77+8+99++++++++++++++++++++++++"
"45099303++7+4+41426++74836+0++46+8+90412+++6+8342"
Returns: "0000+11+222+3333+44444444+5+6666+77+888+999++++++"
"0+7+1+++2++++4++1+8+3++3236+8+9+++1+0+75+2+"
Returns: "00+111+222+333+4+5+6+77+88+9+++++++++++++++"
"1+++++66+920++97+++++2+39++64+++6+++0+0"
Returns: "000+1+22+3+4++6666+7++999++++++++++++++"
"++++++4++4+++++9+9+2++++++8+++++++8+1+++1+90"
Returns: "0+11+2++44++++88+999++++++++++++++++++++++++"
"4173+1+67277+774151510508418+9"
Returns: "00+111111+2+3+4445556777777889"
"9030640461916590+2+979069738"
Returns: "00000+11+2334456666778999999"
"6072172+++08+4+9+24++5+++4+26+8++5+++77++++6"
Returns: "00+1+2222++444+55+666+7777+88+9+++++++++++++"
"53+++++03+8012146852277601945+68++15"
Returns: "000+1111+222+33+44+5555+666+77+888+9"
"++4+997++3"
Returns: "+++3+4+799"
"87+++52+6+355805+4516+2++07331+14+046+37+45475600"
Returns: "00000+111+22+3333+44444+5555555+6666+7777+88+++++"
"3+++++6+++1+5++++6+4++++5707+"
Returns: "0+1++3+4+55+66+77++++++++++++"
"++++++++33+01++++++3++++9+++8+4+++++++++++56+++"
Returns: "0+1++333+4+5+6++8+9++++++++++++++++++++++++++++"
"++7++9+1+++8+2+++++49++3+++++++7829++47+29"
Returns: "+1+222+3+44+++777+88+9999+++++++++++++++++"
"++312004++++++++++++++5+++++++++8++++6+++++6"
Returns: "00+1+2+3+4+5+66++8++++++++++++++++++++++++++"
"30359+54+75+89900902276511+3685646+8679952"
Returns: "0000+11+222+333+44+55555566666777888999999"
"1564915+709+83053+95++97452"
Returns: "00+11+2+33+44+5555567789999"
"1+++++7++++++"
Returns: "+1++++++7++++"
"1+++02+++++7+++++4++++44+++++0++2+++++"
Returns: "00+1+22++444+++7++++++++++++++++++++++"
"7054558826359499967329046666945+586850076++40460"
Returns: "000000++22+3344444455555556666666667778888999999"
"6684126076266092167840+678287759261967+2+269730899"
Returns: "0000+111+2222222+344566666666666777777788888999999"
"+++1++"
Returns: "+1++++"
"+9"
Returns: "+9"
"++2364583++847++100+"
Returns: "00+1+2+33+44+5+6+788"
"+++++++++++++++"
Returns: "+++++++++++++++"
"2347899876667809111+++++++1000000000"
Returns: "0000000000+1111+2+3+4++666+777888999"
"987654321"
Returns: "123456789"
"+++++++23"
Returns: "++2+3++++"
"++++++++++++++++++++++++"
Returns: "++++++++++++++++++++++++"
"33322111++"
Returns: "+111+22333"
"+++00"
Returns: "00+++"