注意到俩者相同的部分,把它整成一个函数,然后需要什么数字就调用这个函数;
#include <iostream>
#include <cstdio>
using namespace std;
int compute(int x,int y){
int sum=0;
while(x!=0){
if(x%10==y) sum=sum*10+y;
x/=10;
}
return sum;
}
int main()
{
int a,da,b,db;
scanf("%d%d%d%d",&a,&da,&b,&db);
int tpa=compute(a,da);
int tpb=compute(b,db);
printf("%d",tpa+tpb);
return 0;
}