トランプのゲームの問題
[java]
public class CircleGame {
public int cardsLeft(String deck) {
boolean end = false;
deck = deck.replaceAll("K", "");
System.out.println(deck);
for(int i=0; i
if( parse(deck.charAt(i)) + parse(deck.charAt(i+1) ) == 13 ) {
deck = deck.substring(0, i) + deck.substring(i+2);
i++;
}
}
while (deck.length() > 1 && parse(deck.charAt(0))+parse(deck.charAt(deck.length()-1)) == 13 )
deck = deck.substring(1, deck.length()-1);
return deck.length();
}
public int parse(char ch) {
if ('A' == ch)
return 1;
else if ('T' == ch)
return 10;
else if('J' == ch)
return 11;
else if('Q' == ch)
return 12;
return ch - '0';
}
}
[/java]