首页 > 代码库 > PAT Basic Level 1006

PAT Basic Level 1006

AC代码

 1 #include <stdio.h>
 2 int main ()
 3 {
 4     int x;
 5     scanf("%d",&x);
 6     int mask = 1;
 7     int temp = x;
 8     while(temp != 0 )
 9     {
10         temp = temp/10;
11         mask = mask * 10; 
12     }
13     mask = mask/10;
14     while (mask > 0)
15     {
16         if(mask == 100)
17         {
18             temp = x/mask;
19             while(temp > 0)
20             {
21                 printf("B");
22                 temp--;
23             }
24             x = x%mask;
25             mask = mask/10;
26         }else
27         if(mask == 10)
28         {
29             temp = x/mask;
30             while(temp > 0)
31             {
32                 printf("S");
33                 temp--;
34             }
35             x = x % mask;
36             mask = mask/10;
37         }else
38         if(mask == 1)
39         {
40             temp = x/mask;
41             int i = 1;
42             while(temp>0)
43             {
44             
45                 printf("%d",i);
46                 i++;
47                 temp--;    
48             }
49             x = x % mask;
50             mask = mask/10;
51         }
52         
53     }
54     return 0 ;
55 }

 

PAT Basic Level 1006