您的位置:首页 > 其它

1016部分A+B

2015-11-03 21:11 363 查看
正整数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 ;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: