/* Author: Yiu Yu Ho This is a simulation problem. Here are the steps of the simulation: (1) Deal cards to player and dealer (2 each) (2) Try all possible number of cards that the player can get (stops when the player's hand exceeds 21) (3) Give remaining cards to dealer until the dealer's hand >= 17 (4) Check result, if any situation results in player winning, then the answer is Yes. If in all situations the dealer wins, the answer is No. */ import java.io.*; import java.util.*; public class nowin { public Scanner in = new Scanner(System.in); public PrintStream out = System.out; public String L; public void main() { String player,dealer; int take,P,D; boolean win; L=in.next(); while(!L.equals("JOKER")) { player=""+L.charAt(0)+L.charAt(2); dealer=""+L.charAt(1)+L.charAt(3); L=L.substring(4); take = 0; win=false; P=eval(player); while(P<=21) { D=eval(dealer,L.substring(take)); if(D>21 || P>=D) { win=true; break; } player+=L.charAt(take); P=eval(player); ++take; } out.println(win?"Yes":"No"); L=in.next(); } } public int eval(String player) { char[] p=player.toCharArray(); int ret,ace,i; ret = ace = 0; for(i=0;i