Advertisement
mhdew

Untitled

Mar 28th, 2019
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.69 KB | None | 0 0
  1. #include<stdio.h>
  2.  
  3. int main()
  4. {
  5.     int t;
  6.     scanf("%d", &t);
  7.     int i=0;
  8.     for(i=1;i<=t;i++){
  9.         int n;
  10.         scanf("%d", &n);
  11.  
  12.         int flag=0; //flag indicates current move. flag=0 current move is from alice, flag=1 means current move if from bob
  13.         while(1){
  14.             if(n<10) break;
  15.  
  16.             //find out the largest digit
  17.             int mx=0;
  18.             int m=n;
  19.             while(1){
  20.                 if(m==0) break;
  21.                 int rem=m%10;
  22.                 m=m/10;
  23.                 if(rem>mx) mx=rem;
  24.             }
  25.  
  26.             //move of game that means subtract a digit from the given number
  27.             n=n-mx;
  28.  
  29.             if(flag==0) flag=1;
  30.             else if(flag==1) flag=0;
  31.         }
  32.  
  33.         if(flag==1){
  34.             printf("Case #%d: Bob\n", i);
  35.         }
  36.         else{
  37.             printf("Case #%d: Alice\n", i);
  38.         }
  39.     }
  40.  
  41.     return 0;
  42.  
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement