C
#include <stdio.h>
int main()
{
int Da=0,Db=0;
long a=0,b=0,Pa=0,Pb=0;
scanf("%ld%d%ld%d",&a,&Da,&b,&Db);
for(; a; a/=10)
{
if(a%10 == Da)
Pa = 10*Pa + Da;
}
for(; b; b/=10)
{
if(b%10 == Db)
Pb = 10*Pb + Db;
}
printf("%ld",Pa+Pb);
return 0;
}
C++
#include <iostream>
using namespace std;
void fun()
{
int Da=0,Db=0;
long a=0,b=0;
int Pa=0,Pb=0;
cin >> a >> Da >> b >> Db;
for(; a; a/=10)
{
if(a%10 == Da)
Pa = Pa*10 + Da;
}
for(; b; b/=10)
{
if(b%10 == Db)
Pb = Pb*10 + Db;
}
cout << Pa+Pb;
}
int main()
{
fun();
return 0;
}