1016. 部分A+B (15)
时间限制
100 ms
内存限制
65536 kB
代码长度限制
8000 B
判题程序
Standard
作者
CHEN, Yue
正整数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的值。
输入样例1:3862767 6 13530293 3输出样例1:
399输入样例2:
3862767 1 13530293 8输出样例2:
0
#include<iostream>
#include<algorithm>
#include<math.h>
using namespace std;
int main(){
string s1,s2;
char ch1,ch2;
int m,n,i,j,a=0,b=0;
cin>>s1>>ch1>>s2>>ch2;
i=count(s1.begin(),s1.end(),ch1);
j=count(s2.begin(),s2.end(),ch2);
m=ch1-'0';
n=ch2-'0';
for(int p=0;p<i;p++)
a+=m*pow(10,p);
for(int q=0;q<j;q++)
b+=n*pow(10,q);
cout<<a+b;
return 0;
}

291

被折叠的 条评论
为什么被折叠?



