1016. 部分A+B

 1 /*
 2  * Main.c
 3  * 1016. 部分A+B
 4  *  Created on: 2014年8月30日
 5  *      Author: Boomkeeper
 6  *******测试通过*********
 7  */
 8 
 9 #include <stdio.h>
10 #include <math.h>
11 
12 int main(void){
13 
14     long a,b;
15     int Da,Db;
16     int Pa=0,Pb=0;
17     int count_a=0,count_b=0;//计数Da、Db个数
18     int i;
19 
20     scanf("%ld %i %ld %i",&a,&Da,&b,&Db);
21 
22     while(a!=0){
23         if(a%10==Da)
24             count_a++;
25         a/=10;
26     }
27     while(b!=0){
28         if(b%10==Db)
29             count_b++;
30         b/=10;
31     }
32 
33     for(i=count_a-1;i>=0;i--){
34         Pa+=Da*pow(10,i);
35     }
36 
37     for(i=count_b-1;i>=0;i--){
38         Pb+=Db*pow(10,i);
39     }
40 
41     printf("%d
",Pa+Pb);
42 
43     return 0;
44 }

题目链接:

http://pat.zju.edu.cn/contests/pat-b-practise/1016

.

原文地址:https://www.cnblogs.com/boomkeeper/p/1016b.html