PAT Basic Level 1016

AC代码

 1 #include <stdio.h>
 2 #include <string.h>
 3 int main ()
 4 {
 5     char string1[12];
 6     char string2[12];
 7     char s1;
 8     char s2;
 9     int ret1 = 0;
10     int ret2 = 0;
11     scanf("%s %c %s %c",&string1,&s1,&string2,&s2);
12     int i;
13     int cnt = 0;
14     for(i = 0;i < strlen(string1);i++)
15     {
16         if(s1 == string1[i])
17         {
18             cnt++;
19         }
20      } 
21      int mask = 1;
22      while(cnt > 0)
23      {
24          ret1 += (int)(s1-'0')*mask;
25          mask = mask*10;
26          cnt--;
27      }
28      for(i = 0;i < strlen(string2);i++)
29      {
30          if(s2 == string2[i])
31          {
32              cnt++;
33          }
34      }
35      mask = 1;
36      while(cnt > 0)
37      {
38          ret2 += (int)(s2-'0')*mask;
39          mask = mask*10;
40          cnt--;
41      }
42      ret1 = ret1 + ret2;
43      printf("%d",ret1);
44      return 0;
45 }

 

posted @ 2016-10-19 11:08  Ponytai1  阅读(128)  评论(0编辑  收藏  举报