2009-01-15 16:44:32來源不明

2008 NPSC D. 沙之國

/*********************************************************/

  1. #include<stdio.h>         
  2. #include<stdlib.h>      
  3. #include<string.h>      
  4. main()      
  5. {      
  6.   int a,b,c,p,temp=0;      
  7.   while(scanf("%d",&a)==1)      
  8.    {          
  9.      for(b=0;b<a;b++)      
  10.      {      
  11.       temp=0;      
  12.       scanf("%d",&p);         
  13.       while(p>0)      
  14.        {      
  15.          while(p>=27)      
  16.           {      
  17.           p=p-27;      
  18.           temp++;      
  19.           }       
  20.           while(p>=9)      
  21.           {      
  22.           p=p-9;      
  23.           temp++;      
  24.           }      
  25.           while(p>=3)      
  26.           {      
  27.           p=p-3;      
  28.           temp++;         
  29.           }      
  30.           while(p>=1)      
  31.           {      
  32.            p--;      
  33.            temp++;        
  34.           }      
  35.        }      
  36.        printf("%d\n",temp);       
  37.      }      
  38.    }        
  39.  return 0;           
  40. }