题目描述
正整数A的“DA(为1位整数)部分”定义为由A中所有DA组成的新整数PA。例如:给定A = 3862767,DA = 6,则A的“6部分”PA是66,因为A中有2个6。
现给定A、DA、B、DB,请编写程序计算PA + PB。
输入
输入在一行中依次给出A、DA、B、DB,中间以空格分隔,其中0 < A, B < 1010。
输出
在一行中输出PA + PB的值。
样例输入
3862767 6 13530293 3 3862767 1 13530293 8
样例输出
399 0
#include <stdio.h>
int main(){
char str[2][100];
int m,n,a=0,b=0,i;
scanf("%s %d %s %d",str[0],&m,str[1],&n);
for(i=0;str[0][i]!='\0';i++){
if((str[0][i]-'0')==m)
a=a*10+(str[0][i]-'0');
}
for(i=0;str[1][i]!='\0';i++){
if((str[1][i]-'0')==n)
b=b*10+(str[1][i]-'0');
}
printf("%d\n",a+b);
return 0;
}