A positive integer is "D A (as an integer) portion" is defined as all A D A new composition of the integer P A . For example: given A=3862767, D A =6, then the "6 part" of A , PA is 66, because there are two 6s in A. Now given A, D A , B, D B , write a program to calculate P A + P B .
Input format:
Enter A, D A , B, D B in sequence on one line, separated by spaces, where 0<A,B<10 10 .
Output format:
Output the value of P A + P B in one line .
Input example 1:
3862767 6 13530293 3
Sample output 1:
399
Input example 2:
3862767 1 13530293 8
Output sample 2:
0
#include <iostream>
using namespace std;
int main()
{
int a,b,m,n;
int result_a=0,result_b=0;
cin >>a>>m>>b>>n;
while(a){
//找到a中的m部分
int tmp=a%10;
if(tmp==m)
result_a=result_a*10+tmp;
a/=10;
}
while(b){
//找到b中的n部分
int tmp=b%10;
if(tmp==n)
result_b=result_b*10+tmp;
b/=10;
}
cout <<result_a+result_b; //两结果相加
return 0;
}