chenxi16

导航

PAT (Basic Level) Practice (中文)1016 部分A+B

 1 #include<cstdio>
 2 #include<cstring>
 3 using namespace std;
 4 const int MAXN=13;
 5 char a[MAXN],b[MAXN];
 6 char da,db;
 7 void read();
 8 long long int deal_a(char a[],char da);
 9 void deal();
10 int main(){
11     read();
12     deal();
13     return 0;
14 }
15 void read(){
16     scanf("%s",a);
17     getchar();
18     scanf("%c",&da);
19     getchar();
20     scanf("%s",b);
21     getchar();
22     scanf("%c",&db);
23 }
24 long long int deal_a(char a[],char da){
25     long long int x;
26     int count=0;
27     for(int i=0;i<strlen(a);i++){
28         if(a[i]==da){
29            count++;
30         }
31     }
32     if(count==0) x = 0;
33     else{
34         x = 0;
35         for(int j=count-1;j>=0;j--){
36             x = x* 10 + (da-'0');
37         }
38     }
39     return x;
40 }
41 void deal(){
42     long long int x = deal_a(a,da);
43     long long int y = deal_a(b,db);
44     long long int z = x + y;
45     printf("%d",z);
46 }
View Code

 

posted on 2020-04-14 16:48  chenxi16  阅读(126)  评论(0编辑  收藏  举报