1016部分A+B

正整数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<string>
#include<math.h>
using namespace std;
//string add(string str1,string str2){
//	reverse(str1.begin(),str1.end());
//	reverse(str2.begin(),str2.end());
//	if(str1.length() < str2.length()){
//		int carry = 0;
//		for(int i = 0;i < str1.length();i++){
//			if()
//		}
//	}
//}
int main(){
	string str_A,str_B;
	char a,b;
	for(;cin>>str_A>>a>>str_B>>b;){
		int count_A = 0,count_B = 0;
		for(int i =0;i < str_A.length();i++){
			if(str_A[i] == a){
				count_A++;
			}
		}
		for(int j =0;j < str_B.length();j++){
			if(str_B[j] == b){
				count_B++;
			}
		}
		long long int sum = 0;
		for(int i = 0;i<count_A;i++){
			sum+= pow(10,i)*(a - '0');
		}
		for(int i = 0;i < count_B;i++){
			sum+= pow(10,i)*(b - '0');
		}
		cout<<sum<<endl;
	}
	return 0 ;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值